Public Member Functions | |
connect ($dsninfo, $flags=0) | |
Connect to a database and log in as the specified user. | |
getDatabaseInfo () | |
getIdGenerator () | |
prepareStatement ($sql) | |
prepareCall ($sql) | |
createStatement () | |
close () | |
applyLimit (&$sql, $offset, $limit) | |
executeQuery ($sql, $fetchmode=null) | |
executeUpdate ($sql) | |
getUpdateCount () | |
Gets the number of rows affected by the data manipulation query. | |
Protected Member Functions | |
beginTrans () | |
Start a database transaction. | |
commitTrans () | |
Commit the current transaction. | |
rollbackTrans () | |
Roll back (undo) the current transaction. |
Definition at line 34 of file MySQLiConnection.php.
MySQLiConnection::applyLimit | ( | &$ | sql, | |
$ | offset, | |||
$ | limit | |||
) |
Implements Connection.
Definition at line 154 of file MySQLiConnection.php.
00155 { 00156 if ( $limit > 0 ) { 00157 $sql .= " LIMIT " . ($offset > 0 ? $offset . ", " : "") . $limit; 00158 } else if ( $offset > 0 ) { 00159 $sql .= " LIMIT " . $offset . ", 18446744073709551615"; 00160 } 00161 }
MySQLiConnection::beginTrans | ( | ) | [protected] |
Start a database transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 200 of file MySQLiConnection.php.
00201 { 00202 if (!mysqli_autocommit($this->dblink, FALSE)) { 00203 throw new SQLException('Could not begin transaction', mysqli_error($this->dblink)); 00204 } 00205 }
MySQLiConnection::close | ( | ) |
Implements Connection.
Definition at line 144 of file MySQLiConnection.php.
00145 { 00146 $ret = mysqli_close($this->dblink); 00147 $this->dblink = null; 00148 return $ret; 00149 }
MySQLiConnection::commitTrans | ( | ) | [protected] |
Commit the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 212 of file MySQLiConnection.php.
00213 { 00214 if (!mysqli_commit($this->dblink)) { 00215 throw new SQLException('Can not commit transaction', mysqli_error($this->dblink)); 00216 } 00217 mysqli_autocommit($this->dblink, TRUE); 00218 }
MySQLiConnection::connect | ( | $ | dsninfo, | |
$ | flags = 0 | |||
) |
Connect to a database and log in as the specified user.
$dsn | the data source name (see DB::parseDSN for syntax) | |
$flags | Any conneciton flags. public |
SQLException |
Implements Connection.
Definition at line 45 of file MySQLiConnection.php.
References ConnectionCommon::$flags, and executeUpdate().
00046 { 00047 if (!extension_loaded('mysqli')) { 00048 throw new SQLException('mysqli extension not loaded'); 00049 } 00050 00051 $this->dsn = $dsninfo; 00052 $this->flags = $flags; 00053 00054 $dbhost = null; 00055 00056 if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') { 00057 $dbhost = ':' . $dsninfo['socket']; 00058 } else { 00059 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; 00060 00061 if (!empty($dsninfo['port'])) { 00062 $dbhost .= ':' . $dsninfo['port']; 00063 } 00064 } 00065 00066 $host = !empty($dsninfo['hostspec']) ? $dsninfo['hostspec'] : null; 00067 $user = !empty($dsninfo['username']) ? $dsninfo['username'] : null; 00068 $pw = !empty($dsninfo['password']) ? $dsninfo['password'] : null; 00069 $port = !empty($dsninfo['port']) ? $dsninfo['port'] : null; 00070 $socket = !empty($dsninfo['socket']) ? $dsninfo['socket'] : null; 00071 $database = !empty($dsninfo['database']) ? $dsninfo['database'] : null; 00072 00073 $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null; 00074 00075 @ini_set('track_errors', true); 00076 00077 $conn = mysqli_connect($host, $user, $pw, $database, $port, $socket); 00078 00079 @ini_restore('track_errors'); 00080 00081 if (!$conn) { 00082 if (($err = @mysqli_error()) != '') { 00083 throw new SQLException("connect failed", $err); 00084 } elseif (empty($php_errormsg)) { 00085 throw new SQLException("connect failed"); 00086 } else { 00087 throw new SQLException("connect failed", $php_errormsg); 00088 } 00089 } 00090 00091 $this->dblink = $conn; 00092 00093 if ($encoding) { 00094 $this->executeUpdate("SET NAMES " . $encoding); 00095 } 00096 }
MySQLiConnection::createStatement | ( | ) |
Implements Connection.
Definition at line 135 of file MySQLiConnection.php.
00136 { 00137 require_once 'creole/drivers/mysqli/MySQLiStatement.php'; 00138 return new MySQLiStatement($this); 00139 }
MySQLiConnection::executeQuery | ( | $ | sql, | |
$ | fetchmode = null | |||
) |
Implements Connection.
Definition at line 166 of file MySQLiConnection.php.
References $result.
00167 { 00168 $this->lastQuery = $sql; 00169 00170 $result = @mysqli_query($this->dblink, $sql); 00171 00172 if (!$result) { 00173 throw new SQLException('Could not execute query', mysqli_error($this->dblink), $sql); 00174 } 00175 00176 return new MySQLiResultSet($this, $result, $fetchmode); 00177 }
MySQLiConnection::executeUpdate | ( | $ | sql | ) |
Implements Connection.
Definition at line 182 of file MySQLiConnection.php.
References $result.
Referenced by connect().
00183 { 00184 $this->lastQuery = $sql; 00185 00186 $result = @mysqli_query($this->dblink, $sql); 00187 00188 if (!$result) { 00189 throw new SQLException('Could not execute update', mysqli_error($this->dblink), $sql); 00190 } 00191 00192 return (int) mysqli_affected_rows($this->dblink); 00193 }
MySQLiConnection::getDatabaseInfo | ( | ) |
Implements Connection.
Definition at line 101 of file MySQLiConnection.php.
00102 { 00103 require_once 'creole/drivers/mysqli/metadata/MySQLiDatabaseInfo.php'; 00104 return new MySQLiDatabaseInfo($this); 00105 }
MySQLiConnection::getIdGenerator | ( | ) |
Implements Connection.
Definition at line 110 of file MySQLiConnection.php.
00111 { 00112 require_once 'creole/drivers/mysqli/MySQLiIdGenerator.php'; 00113 return new MySQLiIdGenerator($this); 00114 }
MySQLiConnection::getUpdateCount | ( | ) |
Gets the number of rows affected by the data manipulation query.
Implements Connection.
Definition at line 239 of file MySQLiConnection.php.
MySQLiConnection::prepareCall | ( | $ | sql | ) |
Reimplemented from ConnectionCommon.
Definition at line 128 of file MySQLiConnection.php.
00128 { 00129 throw new SQLException('MySQL does not support stored procedures.'); 00130 }
MySQLiConnection::prepareStatement | ( | $ | sql | ) |
Implements Connection.
Definition at line 119 of file MySQLiConnection.php.
00120 { 00121 require_once 'creole/drivers/mysqli/MySQLiPreparedStatement.php'; 00122 return new MySQLiPreparedStatement($this, $sql); 00123 }
MySQLiConnection::rollbackTrans | ( | ) | [protected] |
Roll back (undo) the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 225 of file MySQLiConnection.php.
00226 { 00227 if (!mysqli_rollback($this->dblink)) { 00228 throw new SQLException('Could not rollback transaction', mysqli_error($this->dblink)); 00229 } 00230 mysqli_autocommit($this->dblink, TRUE); 00231 }