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/ |
__construct(string $server, string $username, string $password, string $database) : void
Settings with parameters.
stringHostname or IP address of the database server
stringUsername to connect to the database server
stringPassword to login to the database server
stringDatabase
affectedRows() : int
This gives a result only with INSERT, UPDATE, REPLACE and DELETE statements.
intreturns number of affected rowsclose() : bool
boolis true when closing is successful.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.
stringHostname or IP address of the database server
stringUsername to connect to the database server
stringPassword to login to the database server
stringDatabase
boolis true when connection was made succesfullyescapeString(string $string) : string
Special characters in given string are escaped.
stringstring to be escaped
stringreturns escaped string.getInstance() : object
| access | public |
|---|---|
| inherited_from | \Formaid_DbAbstract::getInstance() |
objectlastInsertId() : int
This gives a result only when a field was updated with AUTO_INCREMENT, usually when executing a INSERT query.
intreturns ID for an AUTO_INCREMENT field of last executed query.numRows(mixed $result) : int
This gives a result only with SELECT and SHOW statements.
mixedresult of a db query
intnumber of rowsprepareSqlField(string $field) : string
name of database or table), for use in an SQL query.
| inherited_from | \PrepareQueryInterface::prepareSqlField() |
|---|
stringdatabase or table name
stringformatted field nameprepareSqlValue(string $value) : string
Quotes are added and the submitted value is properly escaped.
| inherited_from | \PrepareQueryInterface::prepareSqlValue() |
|---|
stringvalue of a variable to be used in an SQL string
stringescaped stringquery(string $query) : \result
If a connection with a database was made, the SQL query is executed. If not, a connection is first made.
stringSQL query
\resultresult of queryselectDb(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.
stringDatabase name
boolis true when switching the database was succesfulconnectToServer(string $server, string $username, string $password) : bool
This method makes the actual connection to the MySQL database server.
stringHostname or IP address of the database server
stringUsername to connect to the database server
stringPassword to login to the database server
boolis true when connection was made succesfully_hasConnection() : bool
| inherited_from | \Formaid_DbAbstract::_hasConnection() |
|---|
boolis true when a connection was made._hasQuery(mixed $result) : bool
| inherited_from | \Formaid_DbAbstract::_hasQuery() |
|---|
mixedresult of a SQL query
boolis true when a query was executed.$connection : resource
| access | protected |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$connection |
$database : string
| access | protected |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$database |
$password : string
| access | protected |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$password |
$result : \result
| access | private |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$result |
$server : string
| access | protected |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$server |
$username : string
| access | protected |
|---|---|
| inherited_from | \Formaid_DbAbstract::$$username |
$_instance
| access | private |
|---|---|
| type | object |
| inherited_from | \Formaid_DbAbstract::$$_instance |