Answers

Question and Answer:

  Home  MS SQL Server

⟩ How To Connect to a SQL Server using odbc_connect()?

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 "ggl_SQL_SERVER":

<?php

$con = odbc_connect('ggl_SQL_SERVER','sa','GlobalGuideLine');

if (!$con) {

print("There is a problem with SQL Server connection. ");

} else {

print("The SQL Server connection object is ready. ");

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 'GlobalGuideLine' 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.

 147 views

More Questions for you: