To interact with SQL server in WINDOWS, its based on php version, need to place either mssql.dll or sqlsrv dll's. This is stated clearly in http://in1.php.net/manual/en/mssql.requirements.php . In UNIX / LINUX, need to install the FreeTDS library and use mssql_connect.
Now, use sqlsrv_connect/mssql_connect to connect to server, sqlsrv_query / mssql_query to run a query over the server, sqlsrv_fetch_array / mssql_fetch_array to fetch the data if needed.
Examples:
$server = "xxx.xx.xx.xxx";
$database = "testDb";
$UID = "user";
$PWD = "password";
$sql_query = "EXEC test.Get_Details";
/* For sqlsrv: */
if(function_exists('sqlsrv_connect')){
$connection = sqlsrv_connect($server,array( "Database"=>$database,"UID"=>$UID,"PWD"=>$PWD));
$msqldbobj = sqlsrv_query( $connection, $sql_query);
while( $row = sqlsrv_fetch_array( $msqldbobj, SQLSRV_FETCH_ASSOC) ) {
print_r($row);
}
print_r($row);
}
}
/* For mssql: */
else if(function_exists('mssql_connect')){
$connection = mssql_connect($server,$UID,$PWD);
mssql_select_db($database, $connection);
$msqldbobj = mssql_query($sql_query);
while( $row = mssql_fetch_array($msqldbobj, MSSQL_ASSOC) ) {
print_r($row);
}
print_r($row);
}
}else{
echo 'server drivers not available';
}
No comments:
Post a Comment
Your comment is so valuable as it would help me in my growth of knowledge.