PHP Connection mssql2008/2005 Database (SQLSRV) configuration instance, mssql2008sqlsrv
This article describes the PHP connection mssql2008/2005 database (SQLSRV) configuration method, share to everyone for your reference. Here's how:
PHP Connection mssql2008/2005 Database and the previous connection mssql2000 is not the same, the connection mssql2008/2005 is the need to add PHP to the MSSQL Connection driver extension, and we commonly used in Hp.ini extension= Php_mssql.dll extensions are only available for connection to MSSQL2000, let's take a look at this workaround
1. Download the extension
(1) to go to the official download of a SQL Server Driver for PHP extension pack, I am here to download the http://www.microsoft.com/en-us/download/details.aspx?id=20098 " Remember to download it as if you want to install it first and then unzip it.
(2) You can also download directly from this site (i downloaded from Microsoft Official) "Click here to download directly"
Unzip the downloaded RAR file and you will get a bunch of. dll files
Download the driver, download and install the release program, which has the following files:
Php_pdo_sqlsrv_52_nts.dll
Php_pdo_sqlsrv_52_ts.dll
Php_pdo_sqlsrv_53_nts_vc6.dll
Php_pdo_sqlsrv_53_nts_vc9.dll
Php_pdo_sqlsrv_53_ts_vc6.dll
Php_pdo_sqlsrv_53_ts_vc9.dll
Php_sqlsrv_52_nts.dll
Php_sqlsrv_52_ts.dll
Php_sqlsrv_53_nts_vc6.dll
Php_sqlsrv_53_nts_vc9.dll
Php_sqlsrv_53_ts_vc6.dll
Php_sqlsrv_53_ts_vc9.dll
Sqlserverdriverforphp.chm (manual, English good enough, can see, hehe)
Sqlserverdriverforphp_license.rtf
Sqlserverdriverforphp_readme.htm (Readme file)
2. Add an extension
According to (VC6/VC9) need to choose the extension, my environment is Wamp (php5.2.6/apache2.2.8), I chose Php_sqlsrv_52_ts_vc6.dll,php_pdo_sqlsrv_52_ts_ Vc6.dll These two files, copy to the Ext directory under the WAMP installation directory, my ext directory is in wamp/bin/php/php5.2.6/ext/
3. Configure PHP.ini
(1) Add the following two extensions in the php.ini dynamic extensions:
Extension=php_sqlsrv_52_ts_vc6.dll
Extension=php_pdo_sqlsrv_52_ts_vc6.dll
(2) Extension=php_pdo.dll; remove, turn on the PDO connection extension
(3) Restart Apache
4. Connecting the database (PDO connection)
Copy the Code code as follows: <?php
$servern = "Sfkfk27el8fj\sqltry";
$coninfo =array ("Database" = "Try2", "UID" = "sa", "PWD" = "123");
$conn =sqlsrv_connect ($servern, $coninfo) or Die ("Connection failed!");
$val =sqlsrv_query ($conn, "select * from usertable");
while ($row =sqlsrv_fetch_array ($val)) {
echo $row [1]. "
";
}
Sqlsrv_close ($conn);
?>
5. Example
Examples of links:
The mssql_lib.php file is as follows:
The
copy Code code is as follows: <?php
class DB {
var $con = null;
function __construct ($dbhost, $dbuser, $ Dbpass, $dbname) {
$connectionInfo = array ("UID" = = $dbuser, "PWD" = = $dbpass, "Database" = $dbname);
$ This->con = Sqlsrv_connect ($dbhost, $connectionInfo);
}
Function Query ($sql) {
$result = sqlsrv_query ($this->con, $sql);
}
Function GetRow ($sql) {
$result = sqlsrv_query ($this->con, $sql),
$arr = Array (),
while ($row = Sqlsrv_f Etch_array ($result))
{
$arr [] = $row;
}
return $arr [0];
}
Function GetAll ($sql) {
$result = sqlsrv_query ($this->con, $sql);
$arr = Array ();
while ($row = sq Lsrv_fetch_array ($result))
{
$arr [] = $row;
}
return $arr;
}
Function __destruct () {
unset ($con);
}
}
The test.php page is as follows:
Copy the Code Code as follows://Simple call
$db = new db (Db_host, Db_user, Db_pass, db_name);
$sql = "SELECT * from Crm_order_batch where (status=0 or status was null) and lock_id is not NULL";
$orders _add_list = $db->getall ($sql);
I hope this article is helpful to the PHP database design.
PHP Connection MSSQL Database of several methods _php instance
Note To restart the service for it to take effect. First, establish a connection 1, ODBC Firstly, set up ODBC on the server where the PHP program resides. There are differences between 32-bit and 64-bit operating systems. The 32-bit data source (ODBC) from the management tool in the Control Panel is directly established, and 64-bit is set to run C:windowssyswow64odbcad32.exe from here. 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 as follows: $con = Odbc_connect (' ODBC name ', ' username ', ' password '); 2, connect mssql2000 Copy code code as follows: $con = Mssql_connect (' Database address ', ' username ', ' password '); 3 , the connection mssql2008 copy code code is as follows: $connectionInfo = Array ("UID" = user name, "PWD" = password, "database" = "db name"); $con = sqlsrv_connect (database address, $ ConnectionInfo); second, the input query code this is the same, can be directly written, but also can be verified from the MSSQL after copying over. The simple point is to assign a SQL statement to a variable. Like the following code, copy the code as follows: $query = "SELECT Top 12 * Database name ORDER BY id DESC"; Build the query and take out the data 1, the ODBC Copy Code code is as follows: $result = Odbc_do ($con, $query); while (Odbc_fetch_row ($result)) {$ Variable name = Odbc_result ($result, "field name");} 2, the connection mssql2000 copy code code is as follows: $result = Mssql_query ($con, $query), while ($row =mssql_fetch_array ($result)) {$ Variable name = $row ["Field name "];} 3, the connection mssql2008 copy code code is 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
PHP + MS SQL Server 2005 database connection
Unable to connect to server says the server is not connected
Try adding a port number.
Mssql_connect (' localhost,1433′, USERNAME, PASSWORD);
If not, take a look at the reference articles.
http://www.bkjia.com/PHPjc/897687.html www.bkjia.com true http://www.bkjia.com/PHPjc/897687.html techarticle PHP Connection mssql2008/2005 Database (SQLSRV) configuration instance, mssql2008sqlsrv This article describes the PHP connection mssql2008/2005 database (SQLSRV) configuration method, share to everyone for your reference. ...