phpでデーターベースに接続したい
lolipopサーバーを使用しています。
サブディレクトリー毎にphpのバージョンが設定できるので今回php7.1(cgi版)に指定しました。
そのサブディレクトリー内にindex.phpというファイルを入れてあります。index.phpの内容はmysql
に接続するだけのものです。
発生している問題・エラーメッセージ
データベースにアクセスできません!SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
該当のソースコード
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>テスト</title> </head> <body> <?php// データベースに接続するために必要なデータソースを変数に格納 $dsn = 'mysql:host= mysql***.phy.lolipop.jp; dbname=sample; charset=utf8'; // データベースのユーザー名 $user = 'user1'; // データベースのパスワード $password = 'password'; // tryにPDOの処理を記述 try { // PDOインスタンスを生成 $dbh = new PDO($dsn, $user, $password); // エラー(例外)が発生した時の処理を記述 } catch (PDOException $e) { // エラーメッセージを表示させる echo 'データベースにアクセスできません!' . $e->getMessage(); // 強制終了 exit; }
?>
</body> </html>試したこと
ここに問題に対して試したことを記載してください。
lolipopを使用しているheteml.jpのサーバーにこのファイル(データーベースのアカウントなどはhetemlのアカウントに変更して)をアップロードして試しましたが、このようなエラーは出ませんでした。
(hetemlにも契約していまして、同様のphpファイルをhetemlでも確認したということです)
ただ、hetemlのphpはcgi版ではなくモジュール版です。私が現在契約しているコースではphpをモジュール版に変更できないため確認は出来ていません。
その後何度か接続を試していたところエラー内容が変化しました。
その内容は次の通りです。
データベースにアクセスできません!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
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー