Home >Backend Development >PHP Tutorial >How to connect php5.3 to sqlserver2000_PHP tutorial

How to connect php5.3 to sqlserver2000_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:05:521157browse

We know that the new version of php5.3 does not support the mssql_connect data connection function that comes with mysql. If we need to connect to the sqlserver database, we can only use the com interface to do it.

1.Com link, ADODB.Connection

$rs->Open(‘select * from News where bigclassid = 59 And LeadPostil is null’, $conn, 1, 1);
$count = $rs->RecordCount;
echo "There are {$count} records
";
for($i = 0; $i < $count ; $i++){
The code is as follows
 代码如下 复制代码

$conn = new Com(“ADODB.Connection”);     //实例化一个Connection对象
$connstr = “provider=sqloledb;datasource=.;uid=sa;pwd=123456;database=jnold;”;
$conn->Open($connstr);
$rs = new Com(“ADODB.Recordset”);    //实例化一个Recordcount对象

$rs->Open(‘select * from News where bigclassid = 59 And LeadPostil is null’, $conn, 1, 1);
$count = $rs->RecordCount;
echo “共有{$count}条纪录
”;
for($i = 0; $i < $count ; $i++){

$arr_result[$i]['Title'] = addslashes($rs->Fields(‘Title’)->Value);//标题
$arr_result[$i]['Color'] = addslashes($rs->Fields(‘titlecolor’)->Value?$rs->Fields(‘titlecolor’)->Value:”);//标题颜色
$arr_result[$i]['WenHao'] = addslashes($rs->Fields(‘OtherText’)->Value);//文号

}

Copy code

 代码如下 复制代码

$dbhost = ”;
$dbuser = ”; //你的mssql用户名
$dbpass = ”; //你的mssql密码
$dbname = ”; //你的mssql库名

$connect=odbc_connect(“Driver={SQL Server};Server=$dbhost;Database=$dbname”,”$dbuser”,”$dbpass”);
$sql=”select * from content”;
$exec=odbc_exec($connect,$sql);
while($row = (odbc_fetch_array($exec)))
{
$row['id']   //?取字段值

}

$conn = new Com(“ADODB.Connection”); //Instantiate a Connection object
$connstr = “provider=sqloledb;datasource=.;uid=sa;pwd=123456;database=jnold;”;
$conn->Open($connstr);
$rs = new Com(“ADODB.Recordset”); //Instantiate a Recordcount object

$arr_result[$i]['Title'] = addslashes($rs->Fields('Title')->Value);//Title
$arr_result[$i]['Color'] = addslashes($rs->Fields('titlecolor')->Value?$rs->Fields('titlecolor')->Value:”);/ /Title Color
$arr_result[$i]['WenHao'] = addslashes($rs->Fields(‘OtherText’)->Value);//Document number

} 2.ODBC connection mssql
The code is as follows Copy code
$dbhost = ”;
$dbuser = ”; //Your mssql username
$dbpass = ”; //Your mssql password
$dbname = ”; //Your mssql library name $connect=odbc_connect(“Driver={SQL Server};Server=$dbhost;Database=$dbname”,”$dbuser”,”$dbpass”);
$sql="select * from content";
$exec=odbc_exec($connect,$sql);
while($row = (odbc_fetch_array($exec)))
{
$row['id'] //?Get field value

}
http://www.bkjia.com/PHPjc/630732.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630732.htmlTechArticleWe know that the new version of php5.3 does not support the mssql_connect data connection function that comes with mysql. If you need to connect to sqlserver For the database, we can only use the com interface. 1.Com chain...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn