First, in the php.ini file; Extension=php_pdo_mssql.dll, extension=php_pdo_odbc.dll the semicolon in front of the removal, corresponding to which way to connect the MSSQL. Note To restart the service for it to take effect.
First, establish a connection
1. ODBC
First, set up ODBC on the server where the PHP program resides. There are differences between 32-bit and 64-bit operating systems. 32-bit from the management tool in the Control Panel data Source (ODBC) is directly established, 64-bit to run C:\Windows\SysWOW64\odbcad32.exe
Set from this side. Note: Only the database server is 32, and the data source sets the server to be both 32-bit and 64-bit. As long as two servers establish a consistent number of data source bits.
The following is the ODBC build connection code.
Copy the Code code as follows:
$con = Odbc_connect (' ODBC name ', ' username ', ' password ');
2. Connecting mssql2000
Copy the Code code as follows:
$con = Mssql_connect (' Database address ', ' username ', ' password ');
3. Connecting mssql2008
Copy the Code code as follows:
$connectionInfo = Array ("UID" + user name, "PWD" + = password, "database" + "DB name");
$con = sqlsrv_connect (database address, $connectionInfo);
Second, enter the query code
This is the same, can be directly written, or can be verified from the MSSQL after copying. The simple point is to assign a SQL statement to a variable.
Similar to the following code
Copy the Code code as follows:
$query = "SELECT Top 12 * Database name ORDER BY id DESC";
Third, establish the query and take out the data
1. ODBC
Copy the Code code as follows:
$result = Odbc_do ($con, $query);
while (Odbc_fetch_row ($result))
{
$ Variable name = Odbc_result ($result, "field name");
}
2. Connecting mssql2000
Copy the Code code as follows:
$result = Mssql_query ($con, $query);
while ($row =mssql_fetch_array ($result))
{
$ Variable name = $row ["field name"];
}
3. Connecting mssql2008
Copy the Code code as follows:
$result = sqlsrv_query ($con, $query);
while ($row = Sqlsrv_fetch_array ($result))
{
$ Variable name = $row ["field name"];
}
The SQLSRV library is not included in the php5.3 and later versions. So I want to download it from Microsoft.
Four, close the connection
This is no different from odbc_close (), and Mssql_close () and sqlsrv_close ();
Finally realized: PHP connection MSSQL is less than the function of the connection MSSQL, but also enough. Specific functions can refer to the official PHP manual
http://www.bkjia.com/PHPjc/326589.html www.bkjia.com true http://www.bkjia.com/PHPjc/326589.html techarticle first, in the php.ini file; Extension=php_pdo_mssql.dll, extension=php_pdo_odbc.dll the semicolon in front of the removal, corresponding to which way to connect the MSSQL. Note To restart the service for it to take effect. ...