Basic database class, from which specific database classes derive.

This class provides an interface and basic functionality : - connecting to a database server - selecting a database - performing a query - handle returned data - get info about the query - get info about the database server - close connection to the database - error handling

category Database
package Formaid
author Dieter Adriaenssens
copyright 2006-2013 Dieter Adriaenssens
license GPL
link http://formaid.sourceforge.net/

 Methods

Constructor, defines basic database class.

__construct(string $server, string $username, string $password, string $database) : void

Settings with parameters.

Parameters

$server

string

Hostname or IP address of the database server

$username

string

Username to connect to the database server

$password

string

Password to login to the database server

$database

string

Database

Returns the number of rows that was affected by the last statement.

affectedRows() : bool

This gives a result only with INSERT, UPDATE, REPLACE and DELETE statements.

Returns

boolreturns true if connection was made and a query was executed.

Closes connection to the database

close() : bool
Inherited
inherited_from \DbInterface::close()

Returns

boolis true when closing is successful.

Makes a connection with a database.

connect(string $server, string $username, string $password, string $database) : bool

Uses servername, username, password and database from the configfile, unless they are provided as parameters. The provided parameters are not stored and override the values in the configfile.

First, a connection is made to the database server. After successfully connecting to the database server, a database is selected.

Parameters

$server

string

Hostname or IP address of the database server

$username

string

Username to connect to the database server

$password

string

Password to login to the database server

$database

string

Database

Returns

boolis true when connection was made succesfully

Returns an escaped string.

escapeString(string $string) : bool

Special characters in given string are escaped.

Parameters

$string

string

string to be escaped

Returns

booltrue if string is not empty and if connection was made

Creates a singleton of this class

getInstance() : object
access public

Returns

object

Returns the ID of last executed query.

lastInsertId() : bool

This gives a result only when a field was updated with AUTO_INCREMENT, usually when executing a INSERT query.

Returns

booltrue if a connection was made

Returns the number of rows that was returned by the last statement, or the result provided by a parameter.

numRows(mixed $result) : bool

This gives a result only with SELECT and SHOW statements.

Parameters

$result

mixed

result of a SQL query

Returns

boolreturns true if connection was made and a query was executed.

Formats an sql-field (f.e.

prepareSqlField(string $field) : string

name of database or table), for use in an SQL query.

Quotes are added to the database or table name.

Parameters

$field

string

database or table name

Returns

stringformatted field name

Format a value for an sql statement

prepareSqlValue(string $value) : string

Quotes are added and the submitted value is properly escaped.

Parameters

$value

string

value of a variable to be used in an SQL string

Returns

stringescaped string

Executes an SQL query

query(string $query) : bool

If a connection with a database was made, the SQL query is executed. If not, an error is thrown.

Parameters

$query

string

SQL query

Returns

boolreturns true if the query is not empty and a connection was made

Selects a database

selectDb(string $database) : bool

Uses a database name from the configfile, unless it is provided as a parameter. The provided parameter is not stored and overrides the value in the configfile.

Parameters

$database

string

Database name

Returns

boolis true when switching the database was succesful

Makes a connection with the database server (abstract).

connectToServer(string $server, string $username, string $password) : bool

This method makes the actual connection to the database server. This method is overridden by child classes for a specific database type.

Parameters

$server

string

Hostname or IP address of the database server

$username

string

Username to connect to the database server

$password

string

Password to login to the database server

Returns

boolis true when connection was made succesfully

Checks if a connection was made.

_hasConnection() : bool

Returns

boolis true when a connection was made.

Checks if a query was executed.

_hasQuery(mixed $result) : bool

Parameters

$result

mixed

result of a SQL query

Returns

boolis true when a query was executed.

 Properties

 

$connection : resource
access protected
 

$database : string
access protected
 

$error_message : string
access protected
 

$password : string
access protected
 

$result : \result
access private
 

$server : string
access protected
 

$username : string
access protected
 

$_instance 
access private
type object