How To Connect to a SQL Server using odbc_connect()?
Submitted by: AdministratorIf 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.
Submitted by: Administrator
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.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | How To Start SQL Server Browser Service? |
☺ | What To Perform Pattern Match with the LIKE Operator? |
☺ | How to Create a View using Data from Another View? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |