Created
March 30, 2011 10:43
-
-
Save boxers999/894191 to your computer and use it in GitHub Desktop.
PDO & MSSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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