Public Member Functions | |
connect ($dsninfo, $flags=0) | |
getDatabaseInfo () | |
getIdGenerator () | |
prepareStatement ($sql) | |
createStatement () | |
applyLimit (&$sql, $offset, $limit) | |
Returns false since MSSQL doesn't support this method. | |
close () | |
executeQuery ($sql, $fetchmode=null) | |
executeUpdate ($sql) | |
getUpdateCount () | |
Gets the number of rows affected by the last query. | |
prepareCall ($sql) | |
Creates a CallableStatement object for calling database stored procedures. | |
Protected Member Functions | |
beginTrans () | |
Start a database transaction. | |
commitTrans () | |
Commit the current transaction. | |
rollbackTrans () | |
Roll back (undo) the current transaction. | |
Private Attributes | |
$database | |
Current database (used in mssql_select_db()). |
Definition at line 49 of file MSSQLConnection.php.
MSSQLConnection::applyLimit | ( | &$ | sql, | |
$ | offset, | |||
$ | limit | |||
) |
Returns false since MSSQL doesn't support this method.
Implements Connection.
Definition at line 147 of file MSSQLConnection.php.
MSSQLConnection::beginTrans | ( | ) | [protected] |
Start a database transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 202 of file MSSQLConnection.php.
References $result.
00203 { 00204 $result = @mssql_query('BEGIN TRAN', $this->dblink); 00205 if (!$result) { 00206 throw new SQLException('Could not begin transaction', mssql_get_last_message()); 00207 } 00208 }
MSSQLConnection::close | ( | ) |
Implements Connection.
Definition at line 155 of file MSSQLConnection.php.
00156 { 00157 $ret = @mssql_close($this->dblink); 00158 $this->dblink = null; 00159 return $ret; 00160 }
MSSQLConnection::commitTrans | ( | ) | [protected] |
Commit the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 215 of file MSSQLConnection.php.
References $result.
00216 { 00217 if (!@mssql_select_db($this->database, $this->dblink)) { 00218 throw new SQLException('No database selected'); 00219 } 00220 $result = @mssql_query('COMMIT TRAN', $this->dblink); 00221 if (!$result) { 00222 throw new SQLException('Could not commit transaction', mssql_get_last_message()); 00223 } 00224 }
MSSQLConnection::connect | ( | $ | dsninfo, | |
$ | flags = 0 | |||
) |
Implements Connection.
Definition at line 57 of file MSSQLConnection.php.
References ConnectionCommon::$flags, and Creole::PERSISTENT.
00058 { 00059 if (!extension_loaded('mssql') && !extension_loaded('sybase') && !extension_loaded('sybase_ct')) { 00060 throw new SQLException('mssql extension not loaded'); 00061 } 00062 00063 $this->dsn = $dsninfo; 00064 $this->flags = $flags; 00065 00066 $persistent = ($flags & Creole::PERSISTENT === Creole::PERSISTENT); 00067 00068 $user = $dsninfo['username']; 00069 $pw = $dsninfo['password']; 00070 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; 00071 00072 if (PHP_OS == "WINNT" || PHP_OS == "WIN32") { 00073 $portDelimiter = ","; 00074 } else { 00075 $portDelimiter = ":"; 00076 } 00077 00078 if(!empty($dsninfo['port'])) { 00079 $dbhost .= $portDelimiter.$dsninfo['port']; 00080 } else { 00081 $dbhost .= $portDelimiter.'1433'; 00082 } 00083 00084 $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect'; 00085 00086 if ($dbhost && $user && $pw) { 00087 $conn = @$connect_function($dbhost, $user, $pw); 00088 } elseif ($dbhost && $user) { 00089 $conn = @$connect_function($dbhost, $user); 00090 } else { 00091 $conn = @$connect_function($dbhost); 00092 } 00093 if (!$conn) { 00094 throw new SQLException('connect failed', mssql_get_last_message()); 00095 } 00096 00097 if ($dsninfo['database']) { 00098 if (!@mssql_select_db($dsninfo['database'], $conn)) { 00099 throw new SQLException('No database selected'); 00100 } 00101 00102 $this->database = $dsninfo['database']; 00103 } 00104 00105 $this->dblink = $conn; 00106 }
MSSQLConnection::createStatement | ( | ) |
Implements Connection.
Definition at line 138 of file MSSQLConnection.php.
00139 { 00140 require_once 'creole/drivers/mssql/MSSQLStatement.php'; 00141 return new MSSQLStatement($this); 00142 }
MSSQLConnection::executeQuery | ( | $ | sql, | |
$ | fetchmode = null | |||
) |
Implements Connection.
Definition at line 165 of file MSSQLConnection.php.
References $result.
00166 { 00167 $this->lastQuery = $sql; 00168 if (!@mssql_select_db($this->database, $this->dblink)) { 00169 throw new SQLException('No database selected'); 00170 } 00171 $result = @mssql_query($sql, $this->dblink); 00172 if (!$result) { 00173 throw new SQLException('Could not execute query', mssql_get_last_message()); 00174 } 00175 return new MSSQLResultSet($this, $result, $fetchmode); 00176 }
MSSQLConnection::executeUpdate | ( | $ | sql | ) |
Implements Connection.
Definition at line 181 of file MSSQLConnection.php.
References $result, and getUpdateCount().
00182 { 00183 00184 $this->lastQuery = $sql; 00185 if (!mssql_select_db($this->database, $this->dblink)) { 00186 throw new SQLException('No database selected'); 00187 } 00188 00189 $result = @mssql_query($sql, $this->dblink); 00190 if (!$result) { 00191 throw new SQLException('Could not execute update', mssql_get_last_message(), $sql); 00192 } 00193 00194 return $this->getUpdateCount(); 00195 }
MSSQLConnection::getDatabaseInfo | ( | ) |
Implements Connection.
Definition at line 111 of file MSSQLConnection.php.
00112 { 00113 require_once 'creole/drivers/mssql/metadata/MSSQLDatabaseInfo.php'; 00114 return new MSSQLDatabaseInfo($this); 00115 }
MSSQLConnection::getIdGenerator | ( | ) |
Implements Connection.
Definition at line 120 of file MSSQLConnection.php.
00121 { 00122 require_once 'creole/drivers/mssql/MSSQLIdGenerator.php'; 00123 return new MSSQLIdGenerator($this); 00124 }
MSSQLConnection::getUpdateCount | ( | ) |
Gets the number of rows affected by the last query.
if the last query was a select, returns 0.
SQLException |
Implements Connection.
Definition at line 249 of file MSSQLConnection.php.
References $result.
Referenced by executeUpdate().
00250 { 00251 $res = @mssql_query('select @@rowcount', $this->dblink); 00252 if (!$res) { 00253 throw new SQLException('Unable to get affected row count', mssql_get_last_message()); 00254 } 00255 $ar = @mssql_fetch_row($res); 00256 if (!$ar) { 00257 $result = 0; 00258 } else { 00259 @mssql_free_result($res); 00260 $result = $ar[0]; 00261 } 00262 00263 return $result; 00264 }
MSSQLConnection::prepareCall | ( | $ | sql | ) |
Creates a CallableStatement object for calling database stored procedures.
string | $sql |
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 274 of file MSSQLConnection.php.
00275 { 00276 require_once 'creole/drivers/mssql/MSSQLCallableStatement.php'; 00277 $stmt = mssql_init($sql); 00278 if (!$stmt) { 00279 throw new SQLException('Unable to prepare statement', mssql_get_last_message(), $sql); 00280 } 00281 return new MSSQLCallableStatement($this, $stmt); 00282 }
MSSQLConnection::prepareStatement | ( | $ | sql | ) |
Implements Connection.
Definition at line 129 of file MSSQLConnection.php.
00130 { 00131 require_once 'creole/drivers/mssql/MSSQLPreparedStatement.php'; 00132 return new MSSQLPreparedStatement($this, $sql); 00133 }
MSSQLConnection::rollbackTrans | ( | ) | [protected] |
Roll back (undo) the current transaction.
SQLException |
Reimplemented from ConnectionCommon.
Definition at line 231 of file MSSQLConnection.php.
References $result.
00232 { 00233 if (!@mssql_select_db($this->database, $this->dblink)) { 00234 throw new SQLException('no database selected'); 00235 } 00236 $result = @mssql_query('ROLLBACK TRAN', $this->dblink); 00237 if (!$result) { 00238 throw new SQLException('Could not rollback transaction', mssql_get_last_message()); 00239 } 00240 }
MSSQLConnection::$database [private] |