1.Com链接,ADODB.Connection
/**
* PHP5连接sql Server的两种方法演示代码
*
* @param
* @arrange 网: jb51.cc
**/
$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}条纪录<br />";
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);//文号
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
2.ODBC连接mssql
/**
* PHP5连接sql Server的两种方法演示代码
*
* @param
* @arrange 网: jb51.cc
**/
$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'] //?取字段值
…
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528565.html