php can be connected to sql. There are two ways for PHP to connect to the SQLServer database, namely: 1. Connect through ADO; 2. Connect through the "mssql_connect()" function.
PHP often cooperates with MySQL database, but sometimes it also cooperates with SQL Server database. So how to connect to SQL Server database in PHP?
Can php be connected to sql?
php can be connected to sql. There are two ways for PHP to connect to the SQLServer database: one is to connect through ADO; the other is to connect through the mssql_connect() function. These two connection methods are introduced below.
1. Connecting to SQL Server database through ADO
Using ADO to establish a connection with the SQL Server database is similar to the method of using ADO to establish a connection with the Access database. Establishing a connection is implemented in the conn.php file of this example. The code is as follows:
open($connstr); ?>
2. Connect to SQL Server database through mssql_connect() function
To establish a connection with SQL Server database through mssql_connect() function, you should first configure the php.ini file, remove the comment before extension=php_mssql.dll, and then restart Apache server. The code to establish a connection with the database through the mssql_connect() function is as follows:
For example, the following uses the mssql_connect() function to connect to the SQL Server database, and the connection result is as shown in the figure.
Connect to SQL Server database
The code to connect to SQL Server database is as follows:
The above is the detailed content of Can php connect to sql?. For more information, please follow other related articles on the PHP Chinese website!