简体   繁体   中英

Error "could not find driver" in PHP PDO

I installed on my Ubuntu 14.0.4 Apache,PHP,MySQL separately and I am trying to open a connection to a db and I get the following error "could not find driver". I have tried a lot of solutions but nothing seems to working.

For example: php5-mysql is already in newest version

OR:

PDO
PDO support => enabled
PDO drivers => mysql, odbc, pgsql
PDO Driver for MySQL => enabled
PDO_ODBC
PDO Driver for ODBC (unixODBC) => enabled
PDO Driver for PostgreSQL => enabled

Above part of the code :

<?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);

    require_once 'dbcredentials.php';

    try{

        $dsn = "myslq:host=$dbhost; dbname=$db";
        $dbh = new PDO($dsn, $dbuser, $dbpass);

        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
        $result = $dbh->exec($sql_create_user_tbl);
        // more code  

    }
    catch (PDOException $e) {
        echo $e->getMessage();
    }  

Feel free to share some ideas

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

require_once 'dbcredentials.php';

try{

    $dsn = "mysql:host=$dbhost; dbname=$db";
    $dbh = new PDO($dsn, $dbuser, $dbpass);

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $result = $dbh->exec($sql_create_user_tbl);
    // more code  

}
catch (PDOException $e) {
    echo $e->getMessage();
} 

your mysql spelling is wrong, it should be mysql not myslq

It may be a syntax problem in $dsn. Try to remove space before dbname and fixing "mysql"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM