teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

データベースユーザー名・パスワードの削除

2021/04/12 16:30

投稿

hiziki
hiziki

スコア54

title CHANGED
File without changes
body CHANGED
@@ -13,12 +13,12 @@
13
13
  <?php
14
14
  error_reporting(E_ALL & ~E_NOTICE);
15
15
  require '../password.php';
16
- $link = mysql_connect('localhost', 'c157mjhsbrass', 'PercTpHr');
16
+ $link = mysql_connect('localhost', '(ユーザー名)', '(パスワード)');
17
17
  if (!$link) {
18
18
  die('接続失敗です。'.mysql_error());
19
19
  }
20
20
 
21
- $db_selected = mysql_select_db('c157sqltest', $link);
21
+ $db_selected = mysql_select_db('(ユーザー名)', $link);
22
22
  if (!$db_selected){
23
23
  die('データベース選択失敗です。'.mysql_error());
24
24
  }
@@ -54,7 +54,7 @@
54
54
  ユーザー登録はうまくいくのですが、このようなエラーが出てきました。
55
55
 
56
56
  ```error
57
- Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/clients/client157/web190/web/buin/account/insert.php on line 10
57
+ Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in (ディレクトリ)insert.php on line 10
58
58
  ```
59
59
  調べたところ、MySQLに接続するための構文が廃止されるみたいなことが書いてあったため、[こちらのサイト](http://webkaru.net/php/function-mysqli-connect/)と、[このサイト](http://php5.seesaa.net/article/62432244.html)を参考に次の構文に変更してみました。
60
60
 
@@ -72,9 +72,9 @@
72
72
 
73
73
  // データベースへの接続に必要な変数を指定
74
74
  $host = 'localhost';
75
- $username = 'c157mjhsbrass';
75
+ $username = '(ユーザー名)';
76
- $passwd = 'PercTpHr';
76
+ $passwd = '(パスワード)';
77
- $dbname = 'c157sqltest';
77
+ $dbname = '(データベース名)';
78
78
 
79
79
  // データベースへ接続
80
80
  $db = mysqli_connect($host, $username, $passwd, $dbname);
@@ -111,7 +111,7 @@
111
111
  すると、今度はアカウントの登録もできなくなり、次のエラーが出てきました。
112
112
 
113
113
  ```
114
- Warning: mysql_query() expects parameter 1 to be string, object given in /var/www/clients/client157/web190/web/buin/NA/insert.php on line 26
114
+ Warning: mysql_query() expects parameter 1 to be string, object given in /insert.php on line 26
115
115
  クエリの送信に失敗しました。
116
116
  ```
117
117
  自分が理解できたところは、26行目にエラーが発生していることしか分かりませんでした。