Re: MSSQL and ODBC Connections with PHP on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux