Home > php教程 > PHP源码 > body text

php连接mysql ,mssql ,access,pdo等连接数据库代码

WBOY
Release: 2016-06-08 17:27:03
Original
1093 people have browsed it

本文章提供了四种数据库连接程序,都针对于php的,像php mysql,与mssql是比较常用的,至于php access数据连接也有不秒人在用,还有就是利用php pdo来连接数据库代码我是在用火车头采集数据时来用的。

<script>ec(2);</script>

 
 //php与mysql数据库连接代码
 

 代码如下 复制代码
 mysql_connect('localhost','root','root') or die( 'mysql server stop or use password error!' );
 mysql_select_db('cshouse') or die( 'datebase error' );
 mysql_query("set Names 'GB2312'");


 
 //php 连接access数据库代码
 
 

 代码如下 复制代码
$conn = @new COM("ADODB.Connection") or die ("ADO Connection faild.");
 $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . $path;
 $conn->Open($connstr);


 
 //php 利用pdo连接mdb数据库,这个比较适合于火车头采集数据的用户

 代码如下 复制代码
 $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与mssql 数据库连接代码
 

 代码如下 复制代码
 $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");
  
 /*
  
  好了本站原创文章转载注明来源http://www.111cn.net/phper/php.html
 */
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template