Collections:
odbc_connect() - Connecting to a SQL Server through an ODBC DSN
How To Connect to a SQL Server using odbc_connect()?
✍: Guest
If you have an ODBC DSN (Data Source Name) created linking to a SQL Server, you are ready to connect to the SQL Server through the DSN with ODBC functions. There is no changes needed in the php.ini configuration file.
The tutorial script below shows you how to call odbc_connect() and odbc_close() to connect and disconnect to the SQL Server through the DSN name "FYI_SQL_SERVER":
<?php
$con = odbc_connect('FYI_SQL_SERVER','sa','FYIcenter');
if (!$con) {
print("There is a problem with SQL Server connection.\n");
} else {
print("The SQL Server connection object is ready.\n");
odbc_close($con);
}
?>
If you run this script and get this output: "The SQL Server connection object is ready", your PHP environment and ODBC connection to the SQL Server are working.
Note that 'sa' and 'FYIcenter' used in this script are system administrator login name and password. You may use any other login name and password defined on the SQL Server.
⇒ odbc_data_source() - Listing All DSN Entries
⇐ Testing ODBC DSN Connection Settings
⇑ SQL Server FAQs - PHP ODBC Functions - Connection and Query Execution
2024-07-11, 2056🔥, 0💬
Popular Posts:
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...
How To Look at the Current SQL*Plus System Settings in Oracle? If you want to see the current values...
Where to find Oracle database server tutorials? Here is a collection of tutorials, tips and FAQs for...
Where to find SQL Server database server tutorials? Here is a collection of tutorials, tips and FAQs...
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...