Public Member Functions | |
KjwSql ($sqltype, $hostname, $portnum, $username, $password, $database) | |
Constructor. | |
destroy () | |
Destructor performing cleanup. | |
getType () | |
Get the sql type. | |
connect () | |
Connect to the SQL server. | |
disconnect () | |
Disconnect from the SQL server. | |
beginWork () | |
Begin a transaction / atomic operation. | |
commitWork () | |
Commit a running transaction / atomic operation. | |
rollbackWork () | |
Revert/ignore all from the running transaction / atomic operation. | |
execute ($query) | |
Execute a query. | |
selectAll ($query, $max=-1, $skip=0) | |
Get an entire array from a select query. | |
selectAtom ($query) | |
Get a single value (atom) from a database. | |
selectAtomOrNull ($query) | |
Get a single value (atom) from a database or null if there is no result. | |
selectAtomRow ($query) | |
Get a single row from a database. | |
selectAtomRowOrNull ($query) | |
Get a single row from a database or null if there is no result. | |
safeQuote ($mixed) | |
Makes sure that any variable is quoted like its correct type should be. | |
nameQuote ($string) | |
Quote a name for an object (column or table). | |
insertArray ($table, $args) | |
A safe insert function. | |
updateArray ($table, $args, $where=null) | |
A safe update function. | |
affectedRows () | |
How many rows were affected (touched) by the last INSERT, UPDATE, REPLACE or DELETE query. | |
insertId () | |
Returns the id of the last INSERT clause that uses an IDENTITY/SEQUENCE/AUTO_INCREMENT value. | |
debugStat () | |
Return an array with statistical information about this KjwSql object. | |
_getLastQuery () | |
[PRIVATE] Returns the last query used. | |
_setLastQuery ($query) | |
[PRIVATE] Store the last executed query internally. | |
Public Attributes | |
$_sqltype | |
SQL server type (mysql, pgsql, mssql, etc). | |
$_hostname | |
Server ip/hostname. | |
$_portnum | |
Port number. | |
$_username | |
User name. | |
$_password | |
Password. | |
$_database | |
Database name. | |
$_debug_query_count | |
A query counter. | |
$_last_query | |
The last executed query, stored for debug purposes. |
Use derived classes that actually have a database backend.
Definition at line 32 of file KjwSql.php.
KjwSql::_getLastQuery | ( | ) |
[PRIVATE] Returns the last query used.
Definition at line 395 of file KjwSql.php.
Referenced by KjwMsSql::_execute_3(), selectAll(), selectAtom(), selectAtomOrNull(), selectAtomRow(), and selectAtomRowOrNull().
KjwSql::_setLastQuery | ( | $ | query | ) |
[PRIVATE] Store the last executed query internally.
$query | The query string to store. |
Definition at line 406 of file KjwSql.php.
References KjwObject::trace().
Referenced by KjwMsSql::_execute_1(), KjwPgSql::execute(), and KjwMySql::execute().
KjwSql::affectedRows | ( | ) |
How many rows were affected (touched) by the last INSERT, UPDATE, REPLACE or DELETE query.
It's unspecified if an UPDATE count includes updates that weren't actual changes. I.e. either the WHERE-match-count is returned, or only the subset where the update was a change.
Reimplemented in KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 366 of file KjwSql.php.
References KjwObject::notImplemented().
KjwSql::connect | ( | ) |
Connect to the SQL server.
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 88 of file KjwSql.php.
References KjwObject::notImplemented().
KjwSql::debugStat | ( | ) |
Return an array with statistical information about this KjwSql object.
Definition at line 386 of file KjwSql.php.
KjwSql::destroy | ( | ) |
Destructor performing cleanup.
Don't rely on this being called ever. The user must call it by hand.
Reimplemented from KjwObject.
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 68 of file KjwSql.php.
References disconnect().
KjwSql::disconnect | ( | ) |
Disconnect from the SQL server.
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 97 of file KjwSql.php.
References KjwObject::notImplemented().
Referenced by destroy().
KjwSql::execute | ( | $ | query | ) |
Execute a query.
$query | The query to execute. |
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 128 of file KjwSql.php.
References KjwObject::notImplemented().
Referenced by beginWork(), commitWork(), insertArray(), rollbackWork(), selectAll(), selectAtom(), selectAtomOrNull(), selectAtomRow(), selectAtomRowOrNull(), and updateArray().
KjwSql::getType | ( | ) |
KjwSql::insertArray | ( | $ | table, | |
$ | args | |||
) |
A safe insert function.
$table | The table into which the arguments in $args should be inserted. | |
$args | An associative array of key value pairs to be inserted. If the value is an array, its first element will be used verbatim (e.g. for array('NOW()')). |
Definition at line 294 of file KjwSql.php.
References execute(), nameQuote(), and safeQuote().
KjwSql::insertId | ( | ) |
Returns the id of the last INSERT clause that uses an IDENTITY/SEQUENCE/AUTO_INCREMENT value.
Reimplemented in KjwMsSql, KjwMySql, KjwPgSql, and KjwXmlSql.
Definition at line 377 of file KjwSql.php.
References KjwObject::notImplemented().
KjwSql::KjwSql | ( | $ | sqltype, | |
$ | hostname, | |||
$ | portnum, | |||
$ | username, | |||
$ | password, | |||
$ | database | |||
) |
Constructor.
$sqltype | A string identifier specifying the SQL server brand/make. | |
$hostname | Server name or IP. | |
$portnum | Port number of 0 if default. | |
$username | User name. | |
$password | Password. | |
$database | Database name. |
Definition at line 52 of file KjwSql.php.
References KjwObject::KjwObject().
Referenced by KjwFakeSql::KjwFakeSql(), KjwMsSql::KjwMsSql(), KjwMySql::KjwMySql(), and KjwPgSql::KjwPgSql().
KjwSql::nameQuote | ( | $ | string | ) |
Quote a name for an object (column or table).
For MySQL this would be by surrounding the name with backticks.
$string | An identifier (column or table name) to be quoted. |
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 282 of file KjwSql.php.
References KjwObject::notImplemented().
Referenced by insertArray(), safeQuote(), and updateArray().
KjwSql::safeQuote | ( | $ | mixed | ) |
Makes sure that any variable is quoted like its correct type should be.
Integers and booleans are returned as integers. Strings are returned as quoted strings with all quotes escaped. If the escaping mechanism is not known, all <32 and >127 characters REMOVED, otherwise the escaping for the specific database make is used.
$mixed | The variable that needs to be returned as a safe entity. |
Reimplemented in KjwFakeSql, KjwMsSql, KjwMySql, and KjwPgSql.
Definition at line 256 of file KjwSql.php.
References KjwObject::croak(), and nameQuote().
Referenced by insertArray(), and updateArray().
KjwSql::selectAll | ( | $ | query, | |
$ | max = -1 , |
|||
$ | skip = 0 | |||
) |
Get an entire array from a select query.
You'll want to use this instead of execute() when you're using templates to show a couple of rows.
$query | Everything after the SELECT keyword. | |
$max | (optional) At most $max rows, use -1 to get all. | |
$skip | (optional) Skip $skip rows. |
Definition at line 143 of file KjwSql.php.
References _getLastQuery(), KjwObject::croak(), and execute().
KjwSql::selectAtom | ( | $ | query | ) |
Get a single value (atom) from a database.
We'll croak if there is more than one value or less than one.
$query | Everything after the SELECT keyword. |
Definition at line 165 of file KjwSql.php.
References _getLastQuery(), KjwObject::croak(), and execute().
KjwSql::selectAtomOrNull | ( | $ | query | ) |
Get a single value (atom) from a database or null if there is no result.
We'll croak if there is more than one value.
$query | Everything after the SELECT keyword. |
Definition at line 185 of file KjwSql.php.
References _getLastQuery(), KjwObject::croak(), and execute().
KjwSql::selectAtomRow | ( | $ | query | ) |
Get a single row from a database.
We'll croak if there is more than one value or less than one.
$query | Everything after the SELECT keyword. |
Definition at line 210 of file KjwSql.php.
References _getLastQuery(), KjwObject::croak(), and execute().
KjwSql::selectAtomRowOrNull | ( | $ | query | ) |
Get a single row from a database or null if there is no result.
We'll croak if there is more than one value.
$query | Everything after the SELECT keyword. |
Definition at line 229 of file KjwSql.php.
References _getLastQuery(), KjwObject::croak(), and execute().
KjwSql::updateArray | ( | $ | table, | |
$ | args, | |||
$ | where = null | |||
) |
A safe update function.
$table | The table where rows should be updated with the arguments in $args. | |
$args | An associative array of key value pairs to be inserted. If the value is an array, its first element will be used verbatim (e.g. for array('NOW()')). | |
$where | An optional where-clause (without the "WHERE "). It's your duty to make this clause SQL safe. |
Definition at line 334 of file KjwSql.php.
References execute(), nameQuote(), and safeQuote().
KjwSql::$_database |
KjwSql::$_debug_query_count |
KjwSql::$_hostname |
KjwSql::$_last_query |
KjwSql::$_password |
KjwSql::$_portnum |
KjwSql::$_sqltype |
KjwSql::$_username |