Connect PHP to SQL Server 2008 R2

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Connect PHP to SQL Server 2008 R2

Postby ruxee » 02. March 2012 00:21

I add the step-by-step guide to make it in
http://www.forosdelweb.com/f18/conectarse-ms-sql-server-2008-desde-php-979188/.

Is in spanish but if you want it in english let me know and I post it here.

Regards
Image
ruxee
 
Posts: 5
Joined: 11. April 2007 23:33

Re: Connect PHP to SQL Server 2008 R2

Postby unWing » 25. March 2012 06:41

I've followed your guide correctly and got connected to the server, but when i try to retrieve the records nothing happen. it return blank. Here is the code Im trying to test.

<?php
$serverName = "MyServer";
$connectionInfo = array( "Database"=>"MyDBS");

$conn = sqlsrv_connect($serverName, $connectionInfo);

if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
else
{
echo "Connection established.</br>";
}

$tsql = "SELECT * FROM Personnel";
$stmt = sqlsrv_query($conn, $tsql);

if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}

if (sqlsrv_num_rows($stmt) > 0 ) //not working, returned blank
{
echo "<table cellpadding=10 border=1>";
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";//instead of numeric use the field name $row["CompanyNum"]
echo "<td>".$row[1]."</td>";//$row["EmployeeNum"]
echo "</tr>";
}
echo "</table>";
}
else {
echo "No rows found!";
}

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

?>
unWing
 
Posts: 2
Joined: 25. March 2012 06:16
Operating System: Windows 7

Re: Connect PHP to SQL Server 2008 R2

Postby unWing » 26. March 2012 02:49

I've corrected my previous post and its working now. Thanks
unWing
 
Posts: 2
Joined: 25. March 2012 06:16
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 123 guests