Php connection to mysql, mssql, access, pdo and other connection database code-PHP source code

Source: Internet
Author: User
Tags mdb database php mysql
This article provides four database connection programs for php, such as phpmysql, which are commonly used with mssql. As for phpaccess data connections, in addition, phppdo is used to connect to the database code. I used phppdo to collect data from the locomotive. This article provides four database connection programs for php, such as php mysql, which are commonly used with mssql. As for php access data connections, in addition, I used php pdo to connect to the database code. I used it when collecting data with the locomotive.

Script ec (2); script


// Php and mysql database connection code

The Code is as follows:
Mysql_connect ('localhost', 'root', 'root') or die ('mysql server stop or use password error! ');
Mysql_select_db ('cshouse') or die ('datebaseerror ');
Mysql_query ("set Names 'gb2312 '");



//Php access Database code

The Code is as follows:
$ Conn = @ new COM ("ADODB. Connection") or die ("ADO Connection faild .");
$ Connstr = "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =". $ path;
$ Conn-> Open ($ connstr );



// Php uses pdo to connect to the mdb database, which is suitable for data collection by the locomotive.

The Code is as follows:
$ Path = "F: ontSpiderResult. mdb ";
$ Conn = new PDO ("sqlite: $ path ");
If ($ conn)
{
Echo ('Connection pdo success ');
}
Else
{
Echo ('cnnection pdo fail, plase check database server! ');
}



// Php and mssql database connection code

The Code is as follows:
$ Link = mssql_connect ("127.0.0.1", "sa", "sa") or die ("Can't connect SQL server ");
Mssql_select_db ("frrc", $ link) or die ("Select database failure ");

/*

Good site Original article reprinted to indicate the source of http://www.111cn.net/phper/php.html
*/

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.