连接服务器上的PDO时出错

时间:2014-03-14 12:32:15

标签: php mysql

这是我的代码,它在本地主机上工作但不在服务器中工作     

     $dbtype = 'mysql';                 // Normally mysql
     $host = 'localhost';                   // This is normally set to localhost
     $db_username = 'name';                         // DB username
     $db_password = 'pass';                     // DB password
     $db_name = 'db_name';                          // DB database name
     $dbprefix = 'db_';                 // Do not change unless you need to!
     $cat_table="db_cat";   

    try
    {
        $pdo = new PDO('mysql:host='. $host .';port=2082;dbname='.$db_name, $db_username, $db_password);
     }
    catch (PDOException $e)
    {

        die($e);
    }
    ?>

错误消息

exception 'PDOException' with message 'SQLSTATE[HY000] [2000] mysqlnd cannot connect to
 MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). 
This will store a new, and more secure, hash value in mysql.user. If this user is used in 
other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag
 from your my.cnf file' in /home/jeywigki/public_html/hotel/db/config.php:13 Stack trace: 
#0 /home/jeywigki/public_html/hotel/db/config.php(13): PDO-
>__construct('mysql:host=loca...', 'table', 'pass') #1 /home/jeywigki/public_html/hotel/index.php(3): require_once('/home/jeywigki/...') #2 {main}

请帮助我。 提前谢谢

1 个答案:

答案 0 :(得分:0)

我不确定,但可能是问题。

你可以试试这个:  引号内的mysql:host=$host;dbname=$db_name

  try
    {
        $pdo = new PDO("mysql:host=$host;dbname=$db_name", $db_username, $db_password);
    }
    catch (PDOException $e)
    {
        exit('Error Connecting To DataBase');
    }

docs