Refer to the PHP manual for a summary of the PHP connection to the SQL Server family. There are three main ways of doing this:
First, through the Mssql_ series functions, mainly for the following version of php5.3 and sqlserver2000 and later use. in php.ini; extension=php_mssql.dll;extension=php_msql.dll;extension=php_pdo_mssql.dll; extension=php_pdo_. The semicolon in front of the Odbc.dll is removed.
Second, through the SQLSRV_ series functions, mainly for more than php5.3 version and SQL Server 2005 and later use. You need to download the installation of Microsoft Drivers for PHP for SQL Server driver, address: https://msdn.microsoft.com/library/dn865013.aspx. Download and then unzip the PHP corresponding to the EXT directory. Then open the php.ini file and add the configuration after extension
Extension=php_pdo_sqlsrv_53_ts.dll
Extension=php_sqlsrv_53_ts.dll
Restart Apache and check phpinfo () to make sure Apache has supported sqlsrv. As shown in the following:
and install Sqlncli.msi, this file is the one that assists the Windows environment to access the database server where SQL Server resides
Third, connect the SQL Server series by ODBC mode. ODBC series extensions need to be opened in php.ini. See in the Phpinfo function
Here is the implementation code:
$serverName = "localhost";
$connectionInfo = Array ("Database" = "Jxc_erp", "UID" = "sa", "PWD" = "123456");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn = = = False) {
Die (Print_r (Sqlsrv_errors (), true));
// }
$sql = "SELECT * FROM dbo. A_php ";
$stmt = sqlsrv_query ($conn, $sql);
if ($stmt = = = False) {
Die (Print_r (Sqlsrv_errors (), true));
// }
while ($row = Sqlsrv_fetch_array ($stmt))
{echo $row [0]. " -----". $row [1]."
";}
$con = Odbc_connect (' jxc_erp ', ' sa ', ' 123456 ');
$query = "SELECT * FROM dbo. A_php ";
$result = Odbc_do ($con, $query);
while (Odbc_fetch_row ($result))
{
$list = Odbc_result ($result, "id"); Print_r ($list); Echo '
';
}
$server = "localhost"; Server IP address, if local, can be written as localhost
$uid = "sa"; User name
$pwd = "123456"; Password
$database = "Jxc_erp"; Database name
Making a database connection
$conn =mssql_connect ($server, $uid, $pwd) or Die ("Connect failed");
mssql_select_db ($database, $conn);
Execute Query statement
$query = "SELECT * from a_php";
$row =mssql_query ($query);
Print output Query Results
while ($list =mssql_fetch_array ($row))
// {
Print_r ($list);
echo "
";
// }
?>