Home  >  Article  >  php教程  >  php连接mysql,mssql,acces,pdo等连接数据库代码

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

WBOY
WBOYOriginal
2016-05-25 16:42:161056browse

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

<?php
//php与mysql数据库连接代码
mysql_connect(&#39;localhost&#39;, &#39;root&#39;, &#39;root&#39;) or die(&#39;mysql server stop or use password error!&#39;);
mysql_select_db(&#39;cshouse&#39;) or die(&#39;datebase error&#39;);
mysql_query("set Names &#39;GB2312&#39;");
//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 (&#39;connection pdo success&#39;);
} else {
    echo (&#39;cnnection pdo fail ,plase check database server!&#39;);
}
// php与mssql 数据库连接代码
$link = mssql_connect("127.0.0.1", "sa", "sa") or die("Can&#39;t connect sql server");
mssql_select_db("frrc", $link) or die("Select database failure");


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