PDO connection database prompts could not find driver solution

Source: Internet
Author: User
Tags dsn windows download

Database connection: We analyze the PDO connection database through the following example.

The code is as follows Copy Code

<?php
$dbms = ' MySQL '; Database type Oracle with ODI, for developers, using a different database, just change this, do not have to remember so many functions
$host = ' localhost '; Database host Name
$dbName = ' Test '; The database used
$user = ' root '; Database connection user Name
$pass = '; The corresponding password
$DSN = "$dbms: host= $host;d bname= $dbName";
//

try {
$DBH = new PDO ($DSN, $user, $pass); Initializes a PDO object, which is the creation of a database connection object $DBH
echo "Connect successfully <br/>";
/* You can also do a search operation

foreach ($dbh->query (' SELECT * from FOO ') as $row) {
Print_r ($row); You can use Echo ($GLOBAL); To see these values
}
*/
$DBH = null;
catch (Pdoexception $e) {
Die ("error!:"). $e->getmessage (). "<br/>");
}
The default is not a long connection, and if you need a database long connection, you need to add a final parameter: Array (pdo::attr_persistent => true) to this:
$db = new PDO ($DSN, $user, $pass, Array (pdo::attr_persistent => true));

?>

The result appears could not find driver error hint, then the reason for the search is not open php_pdo_mysql.dll template caused, know why the solution is simple.

Windows Download Modify PHP.ini

The code is as follows Copy Code

Extension=php_pdo.dll
Extension=php_pdo_mysql.dll
Extension=php_pdo_pgsql.dll
Extension=php_pdo_sqlite.dll
Extension=php_pdo_mssql.dll
Extension=php_pdo_odbc.dll
Extension=php_pdo_firebird.dll
; Extension=php_pdo_oci8.dll

A variety of PDO drivers, can be added to the full plus, but the back of the Php_pdo_oci8.dll, because I did not install the Oralce database, so without this, use a semicolon to annotate it, restart the Apache on it. Of course, if you use a different database, open the corresponding module on the OK.

If you are under Linux, be sure that the module pdo_mysql.so has been compiled into PHP.

Add under PHP.ini:

  code is as follows copy code

extension= pdo_mysql.so

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.