欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php5.3中连接sqlserver2000的两种方法(com与ODBC)_PHP教程

程序员文章站 2022-05-12 15:17:58
...
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'] //?取字段值

}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326416.htmlTechArticle1.Com链接,ADODB.Connection 复制代码 代码如下: $conn = new Com("ADODB.Connection"); //实例化一个Connection对象 $connstr = "provider=sqloledb;datasource=.;uid=sa;p...