Home  >  Article  >  Backend Development  >  Two ways to connect to sqlserver2000 in php5.3 (com and ODBC)_PHP tutorial

Two ways to connect to sqlserver2000 in php5.3 (com and ODBC)_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:53765browse

1.Com link, ADODB.Connection

Copy code The code is as follows:

$ conn = new Com("ADODB.Connection"); //Instantiate a Connection object
$connstr = "provider=sqloledb;datasource=.;uid=sa;pwd=123456;database=jnold;";
$conn->Open($connstr);
$rs = new Com("ADODB.Recordset"); //Instantiate a Recordcount object

$rs->Open('select * from News where bigclassid = 59 And LeadPostil is null', $conn, 1, 1);
$count = $rs->RecordCount;
echo "There are {$count} records in total
";
for($i = 0; $i < $count ; $i++){

$arr_result[$i]['Title'] = addslashes($rs-> Fields('Title')->Value);//Title
$arr_result[$i]['Color'] = addslashes($rs->Fields('titlecolor')->Value?$rs ->Fields('titlecolor')->Value:");//Title Color
$arr_result[$i]['WenHao'] = addslashes($rs->Fields('OtherText')- >Value);//Document number

}


2.ODBC connection mssql

Copy code The code is as follows:

$dbhost = ";
$dbuser = "; //Your mssql username
$dbpass = "; //Your mssql password
$dbname = "; //Your mssql library name

$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'] //? Get field value

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326416.htmlTechArticle1.Com link, ADODB.Connection Copy the code as follows: $conn = new Com("ADODB.Connection" ); //Instantiate a Connection object $connstr = "provider=sqloledb;datasource=.;uid=sa;p...
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