Skip to content

Instantly share code, notes, and snippets.

@boxers999
Created March 30, 2011 10:43
Show Gist options
  • Save boxers999/894191 to your computer and use it in GitHub Desktop.
Save boxers999/894191 to your computer and use it in GitHub Desktop.
PDO & MSSQL
<?php
/*
Downoad the new sqlsrv20 drivers from :- http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05
Copy to your php extensions directort and add to php.ini (Make sure you pick Thread Safe or None Thread Safe and the correct C compiler version. See top of phpinfo for compiler version).
I had ro rename :-
php_sqlsrv_53_nts_vc9.dll to php_sqlsrv.dll
php_pdo_sqlsrv_53_nts_vc9.dll to php_pdo_sqlsrv.dll
In order for the extensions to load
(php.ini)
extension=php_sqlsrv.dll
extension=php_pdo_sqlsrv.dll
*/
try{
$dbh = new PDO( "sqlsrv:server=10.131.6.67;Database = *********2011", '*maintenance', '****');
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM tbl_cost_centre";
$stmt = $dbh->prepare($sql);
#$stmt->bindValue(':usrnQuery', $usrnQuery.'%', PDO::PARAM_INT);
if($stmt->execute()){
echo $stmt->debugDumpParams();
$results=$stmt->fetchAll();
foreach($results as $row){
echo "{$row['costCentreName']}".PHP_EOL;
}
}
} catch (PDOException $e) {
echo 'Error!: '. $e->getMessage()."<br>";
exit();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment