Home >php教程 >php手册 >php5.3怎么连接sqlserver2000

php5.3怎么连接sqlserver2000

WBOY
WBOYOriginal
2016-06-13 10:08:521115browse

我们知道新版的php5.3是不支持mysql自带的mssql_connect这个数据连接函数,如果需要连接sqlserver数据库,我们只能使用了com 接口来做哦。

1.Com链接,ADODB.Connection

 代码如下 复制代码

$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

$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);//文号

}

2.ODBC连接mssql

 代码如下 复制代码

$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']   //?取字段值

}

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