Re: MSSQL and ODBC Connections with PHP on Windows
| From: | Sascha Meyer | Date: | Wed, 18 Jun 2008 15:27:55 +0000 |
| Subject: | Re: MSSQL and ODBC Connections with PHP on Windows | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-28938@lists.php.net to get a copy of this message | ||
I would recommend using PDO for MSSQL, because it performs better in most.
You have to enable both php_pdo.dll and php_pdo_mssql.dll in your php.ini, restart the web server
and you should be ready to go.
Here's a sample code taken from http://de.php.net/manual/en/ref.pdo-dblib.php
[CODE]
<?php
try {
$hostname = "myhost";
$port = 1433;
$dbname = "tempdb";
$username = "dbuser";
$pw = "password";
$dbh = new PDO
("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$stmt = $dbh->prepare("select name from master..sysdatabases where name =
db_name()");
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
?>
[/CODE]
I especially like the fetchAll() function, that's really fast!
Best regards,
Sascha
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser