MySQL database class

This class provides specific functionality to connect to a MySQL database : - 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() : int

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

Returns

intreturns number of affected rows

Closes connection to the database

close() : bool

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. When a database parameter is provided, a database is selected after successfully connecting to the database server.

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) : string

Special characters in given string are escaped.

Parameters

$string

string

string to be escaped

Returns

stringreturns escaped string.

Creates a singleton of this class

getInstance() : object
Inherited
access public
inherited_from \Formaid_DbAbstract::getInstance()

Returns

object

Returns the ID of last executed query.

lastInsertId() : int

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

Returns

intreturns ID for an AUTO_INCREMENT field of last executed query.

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

numRows(mixed $result) : int

This gives a result only with SELECT and SHOW statements.

Parameters

$result

mixed

result of a db query

Returns

intnumber of rows

Formats an sql-field (f.e.

prepareSqlField(string $field) : string
Inherited

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

inherited_from \PrepareQueryInterface::prepareSqlField()

Parameters

$field

string

database or table name

Returns

stringformatted field name

Format a value for an sql statement

prepareSqlValue(string $value) : string
Inherited

Quotes are added and the submitted value is properly escaped.

inherited_from \PrepareQueryInterface::prepareSqlValue()

Parameters

$value

string

value of a variable to be used in an SQL string

Returns

stringescaped string

Executes an SQL query

query(string $query) : \result

If a connection with a database was made, the SQL query is executed. If not, a connection is first made.

Parameters

$query

string

SQL query

Returns

\resultresult of query

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 a MySQL database server.

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

This method makes the actual connection to the MySQL database server.

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
Inherited
inherited_from \Formaid_DbAbstract::_hasConnection()

Returns

boolis true when a connection was made.

Checks if a query was executed.

_hasQuery(mixed $result) : bool
Inherited
inherited_from \Formaid_DbAbstract::_hasQuery()

Parameters

$result

mixed

result of a SQL query

Returns

boolis true when a query was executed.

 Properties

 

$connection : resource
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$connection
 

$database : string
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$database
 

$error_message : string
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$error_message
 

$password : string
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$password
 

$result : \result
Inherited
access private
inherited_from \Formaid_DbAbstract::$$result
 

$server : string
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$server
 

$username : string
Inherited
access protected
inherited_from \Formaid_DbAbstract::$$username
 

$_instance 
Inherited
access private
type object
inherited_from \Formaid_DbAbstract::$$_instance