Last active
December 3, 2018 06:54
-
-
Save anestan/3f8cfdbef085588f98c06ebd3b9150bc to your computer and use it in GitHub Desktop.
connect php 7 to sql server 2014
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
# download ini di github | |
https://github.com/microsoft/msphpsql/releases | |
* sesuaikan dengan php versionnya, check di | |
http://localhost/dashboard/phpinfo.php | |
https://github.com/Microsoft/msphpsql/releases/download/v5.3.0/Windows-7.0.zip | |
* extract zip folder nya, lalu pilih folder sesuai tipe xampp nya. (tipe nya 32 bit di gw) | |
`php_pdo_sqlsrv_7_ts.dll` copy lalu taro di xampp/php/ext | |
* lihat detail di comment |
<?php
try {
$dsn = "sqlsrv:Server=xxx;Database=xxx";
$conn = new PDO($dsn, "sa", "xxx");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch(Exception $e) {
die( print_r( $e->getMessage() ) );
}
$tsql = "SELECT top 50 item, description FROM item_mst";
$getResults = $conn->prepare( $tsql );
$getResults->execute();
$results = $getResults->fetchAll(PDO::FETCH_BOTH);
foreach($results as $row) {
echo $row['item'].' '.$row['description'];
echo '<br>';
}
?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy lalu taro di folder xampp/php/ext
lalu edit php.ini, tambahkan line sesuai nama extension yang sudah di download