PHP connection MySQL, MSSQL, ACCESS,PDO, etc. connection database code

Source: Internet
Author: User
Tags mdb database mssql php and php and mysql access database mysql database


//php and MySQL database connection code

The code is as follows Copy Code
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 connects Access database code

The code is as follows Copy Code
$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 more suitable for the user who collects data from the locomotive

The code is as follows Copy Code
$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

  code is as follows copy code
  $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 reproduced in the source http://www.111cn.net/phper/php.html
 */
Related Article

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.