php5.3 How to connect sqlserver2000_php tutorial

Source: Internet
Author: User
Tags odbc connection
We know that the new version of php5.3 is not supported by the MySQL mssql_connect this data connection function, if you need to connect SQL Server database, we can only use the COM interface to do OH.

1.Com link, ADODB. Connection

The code is as follows Copy Code

$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 = Leadpostil and "is null ', $conn, 1, 1);
$count = $rs->recordcount;
echo "Total {$count} records
”;
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);//Text number

}

2.ODBC Connection MSSQL

The code is as follows Copy Code

$dbhost = ";
$dbuser = "; Your MSSQL user name
$dbpass = "; Your MSSQL code.
$dbname = "; The name of your MSSQL library

$connect =odbc_connect ("Driver={sql Server}; server= $dbhost;D atabase= $dbname "," $dbuser "," $dbpass ");
$sql = "SELECT * from Content";
$exec =odbc_exec ($connect, $sql);
while ($row = (Odbc_fetch_array ($exec)))
{
$row [' ID ']//? Fetch field Value
...
}

http://www.bkjia.com/PHPjc/630732.html www.bkjia.com true http://www.bkjia.com/PHPjc/630732.html techarticle we know that the new version of php5.3 is not supported by the MySQL mssql_connect this data connection function, if you need to connect SQL Server database, we can only use the COM interface to do OH. 1.Com Chain ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.