php5.3中连接sqlserver2000的两种方法(com与ODBC)
程序员文章站
2022-07-06 18:57:01
1.com链接,adodb.connection 复制代码 代码如下: $conn = new com("adodb.connection"); //实例化一个connec...
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}条纪录<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);//文号
}
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'] //?取字段值
…
}
复制代码 代码如下:
$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);//文号
}
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'] //?取字段值
…
}
上一篇: 今天给婆婆买了几件衣服
下一篇: 昨天值急诊班