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 */ |