###前提・実現したいこと
PHP7(CGI版)でMySQL5にPDOによるSQL処理を行なおうとしています。
下記のソースコードを実行したところ、以下のエラーメッセージが発生しました。
※元のPHPは5.1.6。htaccessでphp7で動作させています。
###発生している問題・エラーメッセージ
Error: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
###該当のソースコード
$dsn = 'mysql:dbname=DB_NAME;host=localhost;charset=utf8'; $user = 'USER'; $password = 'PASSWORD'; $sql = "update TABLE_NAME set a='1', b='2' where cd='001'"; try{ $dbh = new PDO($dsn, $user, $password); $stmt = $dbh -> prepare($sql); $stmt->execute($sql); }catch(PDOException $e){ die('Error:'.$e->getMessage()); }
###試したこと
・my.cnfのold_passwordsを0に変更。
・MySQLのパスワードを41byteハッシュに変更。(set password for 'user'@'localhost' = 'password';)
・mysqldの再起動
・apacheの再起動
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/01 09:12