我们知道新版的php5.3是不支持mysql自带的mssql_connect这个数据连接函数,如果需要连接sqlserver数据库,我们只能使用了com 接口来做.
1.Com链接 ADODB.Connection,代码如下:
- $conn = new Com(“ADODB.Connection”);
- $connstr = “provider=sqloledb;datasource=.;uid=sa;pwd=123456;database=jnold;”;
- $conn->Open($connstr);
- $rs = new Com(“ADODB.Recordset”);
- $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 = ”;
- $dbpass = ”;
- $dbname = ”;
- $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']
- …
- }
|