Skip to content

Instantly share code, notes, and snippets.

@anderson-marin26
Created April 3, 2017 14:49
Show Gist options
  • Save anderson-marin26/df76cba5b78dae49db3bc3b80134a2de to your computer and use it in GitHub Desktop.
Save anderson-marin26/df76cba5b78dae49db3bc3b80134a2de to your computer and use it in GitHub Desktop.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$serverName = "192.168.0.95";
$connectionOptions = array(
"Database" => "vanrooycrm_2",
"Uid" => "sa",
"PWD" => "VanrooY2015"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
//Select Query
$tsql= "SELECT @@Version as SQL_VERSION";
//Executes the query
$getResults= sqlsrv_query($conn, $tsql);
//Error handling
if ($getResults == FALSE)
die(FormatErrors(sqlsrv_errors()));
?>
<h1> Results : </h1>
<?php
while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
echo ($row['SQL_VERSION']);
echo ("<br/>");
}
sqlsrv_free_stmt($getResults);
function FormatErrors( $errors )
{
/* Display errors. */
echo "Error information: <br/>";
foreach ( $errors as $error )
{
echo "SQLSTATE: ".$error['SQLSTATE']."<br/>";
echo "Code: ".$error['code']."<br/>";
echo "Message: ".$error['message']."<br/>";
}
}
$sql = "SELECT * FROM dbo.vwMonitorTV1";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
echo "<pre>";
print_r($row);
echo "</pre>";
}
sqlsrv_free_stmt( $stmt);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment