@darion
To connect to a SQL Server database with PHP, you can use the following steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$serverName = "your_server_name"; $connectionOptions = array( "Database" => "your_database_name", "Uid" => "your_username", "PWD" => "your_password" ); $conn = sqlsrv_connect($serverName, $connectionOptions); if (!$conn) { die(print_r(sqlsrv_errors(), true)); } else { echo "Connected to SQL Server successfully"; } |
Replace "your_server_name", "your_database_name", "your_username", and "your_password" with your own server details.
1 2 3 4 5 6 7 8 |
$sql = "SELECT * FROM your_table"; $query = sqlsrv_query($conn, $sql); while ($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)) { echo $row['column_name'] . "<br>"; } sqlsrv_free_stmt($query); |
Remember to replace "your_table" and "column_name" with your own table and column names.
1
|
sqlsrv_close($conn); |
By following these steps, you can easily connect to a SQL Server database with PHP and perform various SQL operations.