質問編集履歴

6

情報の追記

2023/02/15 10:58

投稿

tetejiro
tetejiro

スコア15

test CHANGED
File without changes
test CHANGED
@@ -29,7 +29,7 @@
29
29
 
30
30
  ["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "42S02" ["file":protected]=> string(57) "C:\xampp\htdocs\portfolio_作業用\new-db\new-select.php" ["line":protected]=> int(20) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(57) "C:\xampp\htdocs\portfolio_作業用\new-db\new-select.php" ["line"]=> int(20) ["function"]=> string(7) "execute" ["class"]=> string(12) "PDOStatement" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(6) { ["file"]=> string(54) "C:\xampp\htdocs\portfolio_作業用\shitumon\hozon.php" ["line"]=> int(76) ["function"]=> string(7) "dbQuery" ["class"]=> string(7) "DbQuery" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(230) " INSERT INTO question (whose, whom, situation, goal, what, why, try0, return1) VALUES (112,110,'件名','','詳細','','その他','必要') " } } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "42S02" [1]=> int(1146) [2]=> string(38) "Table 'portfolio.latest' doesn't exist" } }
31
31
  ```
32
- 'portfolio.latest' doesn't exist"  latest 指定していないのに、インサートするテーブルに指定されていることになっているようです。理由が分かりません。
32
+ 'portfolio.latest' doesn't exist" に関して latest 指定していないのに、インサートするテーブルに指定されていることになっているようです。理由が分かりません。
33
33
 
34
34
  ### 該当のソースコード
35
35
 
@@ -72,6 +72,7 @@
72
72
  - XAMPP自体の再インストールを実施しました。エラー内容に変化はありませんでした。
73
73
  - 入れようとしている変数の値をベタ打ち(固定値)でインサートを行ってみましたが、エラー内容に変化はありませんでした。
74
74
  - phpMyAdmin上で、実行しても同じエラーが出ます。(#1146 - 表 'portfolio.latest' は存在しません。)
75
+ - latest での検索結果(対象:作業フォルダ丸ごと)は該当なしでした。
75
76
 
76
77
  ### 補足情報(FW/ツールのバージョンなど)
77
78
 
@@ -128,3 +129,45 @@
128
129
  }
129
130
  }
130
131
  ```
132
+
133
+ ###### new-const.php
134
+ (DBの接続方法などは適切でないと思ったので、別ブランチにて修正してあります。)
135
+ ```php
136
+ <?php
137
+ //データベースの定数の定義
138
+ class ConstDb
139
+ {
140
+ public const dsn = '----割愛';
141
+ public const user = '----割愛';
142
+ public const password = '----割愛';
143
+
144
+ const task = 'task';
145
+ const bytime1 = 'bytime1';
146
+ const bytime2 = 'bytime2';
147
+ const emotion = 'emotion';
148
+ const time1 = 'time1';
149
+ const time2 = 'time2';
150
+ const attention = 'attention';
151
+ const strong1 = 'strong1';
152
+ const strong2 = 'strong2';
153
+ const strong3 = 'strong3';
154
+
155
+ function ConnectDb($dsn, $user, $password)
156
+ {
157
+ $dsn = self::dsn;
158
+ $user = self::user;
159
+ $password = self::password;
160
+ try {
161
+ $dbh = new PDO($dsn, $user, $password, [
162
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
163
+ PDO::ATTR_EMULATE_PREPARES, false
164
+ ]);
165
+ } catch (Exception $e) {
166
+ var_dump($e);
167
+ exit('接続エラーです。<a href="../registration/index.php">もどる</a>');
168
+ }
169
+ return $dbh;
170
+ }
171
+ }
172
+ ```
173
+

5

試したことの追加

2023/02/15 07:31

投稿

tetejiro
tetejiro

スコア15

test CHANGED
File without changes
test CHANGED
@@ -103,7 +103,7 @@
103
103
  $dbh = null;
104
104
  } catch (Exception $e) {
105
105
  var_dump($e);
106
- exit($query); //'セレクトできませんでした。<a href="../registration/index.php">もどる</a>'
106
+ exit($query);
107
107
  }
108
108
  return $rec;
109
109
  }
@@ -122,7 +122,7 @@
122
122
  $dbh = null;
123
123
  } catch (Exception $e) {
124
124
  var_dump($e);
125
- exit($query); //'セレクトできませんでした。<a href="../registration/index.php">もどる</a>'
125
+ exit($query);
126
126
  }
127
127
  return $rec;
128
128
  }

4

コードの追記

2023/02/15 07:25

投稿

tetejiro
tetejiro

スコア15

test CHANGED
File without changes
test CHANGED
@@ -33,7 +33,7 @@
33
33
 
34
34
  ### 該当のソースコード
35
35
 
36
- ###### ソースコード①:クエリ部分
36
+ ###### ソースコード①:クエリ部分(new-select.php)
37
37
  ```
38
38
  function dbQuery($query) {
39
39
  $ConstDb = new ConstDb();
@@ -81,3 +81,50 @@
81
81
  テーブル名が不適切なものがありますが、
82
82
  このエラーを直してから修正したいと思っていますのでご容赦ください。
83
83
 
84
+ ###### new-select.php全文
85
+ ```php
86
+ <?php
87
+ require_once 'new-const.php';
88
+
89
+ class DbQuery {
90
+
91
+ // FETCH_ASSOC
92
+ function dbQuery($query) {
93
+ $ConstDb = new ConstDb();
94
+ $dsn = ConstDb::dsn;
95
+ $user = ConstDb::user;
96
+ $password = ConstDb::password;
97
+
98
+ try {
99
+ $dbh = $ConstDb->ConnectDb($dsn, $user, $password);
100
+ $stmt = $dbh->prepare($query);
101
+ $stmt->execute();
102
+ $rec = $stmt->fetchAll(PDO::FETCH_ASSOC);
103
+ $dbh = null;
104
+ } catch (Exception $e) {
105
+ var_dump($e);
106
+ exit($query); //'セレクトできませんでした。<a href="../registration/index.php">もどる</a>'
107
+ }
108
+ return $rec;
109
+ }
110
+
111
+ // fetch_group
112
+ function selectFetchAll($query) {
113
+ $ConstDb = new ConstDb();
114
+ $dsn = ConstDb::dsn;
115
+ $user = ConstDb::user;
116
+ $password = ConstDb::password;
117
+ try {
118
+ $dbh = $ConstDb->ConnectDb($dsn, $user, $password);
119
+ $stmt = $dbh->prepare($query);
120
+ $stmt->execute();
121
+ $rec = $stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP);
122
+ $dbh = null;
123
+ } catch (Exception $e) {
124
+ var_dump($e);
125
+ exit($query); //'セレクトできませんでした。<a href="../registration/index.php">もどる</a>'
126
+ }
127
+ return $rec;
128
+ }
129
+ }
130
+ ```

3

インデントが分かりやすいように全角にしていましたが、半角に戻しました。

2023/02/15 05:20

投稿

tetejiro
tetejiro

スコア15

test CHANGED
File without changes
test CHANGED
@@ -36,17 +36,17 @@
36
36
  ###### ソースコード①:クエリ部分
37
37
  ```
38
38
  function dbQuery($query) {
39
-  $ConstDb = new ConstDb();
39
+ $ConstDb = new ConstDb();
40
-  $dsn = ConstDb::dsn;
40
+ $dsn = ConstDb::dsn;
41
-  $user = ConstDb::user;
41
+ $user = ConstDb::user;
42
-  $password = ConstDb::password;
42
+ $password = ConstDb::password;
43
43
 
44
-  try {
44
+ try {
45
-   $dbh = $ConstDb->ConnectDb($dsn, $user, $password);
45
+ $dbh = $ConstDb->ConnectDb($dsn, $user, $password);
46
-   $stmt = $dbh->prepare($query);
46
+ $stmt = $dbh->prepare($query);
47
-   $stmt->execute();
47
+ $stmt->execute();
48
-   $rec = $stmt->fetchAll(PDO::FETCH_ASSOC);
48
+ $rec = $stmt->fetchAll(PDO::FETCH_ASSOC);
49
-   $dbh = null;
49
+ $dbh = null;
50
50
 
51
51
  ⇒$recをreturn
52
52
  ```
@@ -56,12 +56,12 @@
56
56
  ###### ソースコード②:クエリ文字列を①に渡す部分
57
57
  ```
58
58
  require_once '../new-db/new-select.php';
59
- $DBQuery = new DBQuery();
59
+ $DBQuery = new DBQuery();
60
- $DBQuery->dbQuery('
60
+ $DBQuery->dbQuery('
61
-  INSERT INTO question
61
+ INSERT INTO question
62
-  (whose, whom, situation, goal, what, why, try0, return1)
62
+ (whose, whom, situation, goal, what, why, try0, return1)
63
-  VALUES
63
+ VALUES
64
-  ('.$honnin.','.$code.',\''.$situation.'\',\''.$goal.'\',\''.$what.'\',\''.$why.'\',\''.$try.'\',\''.$return1.'\')
64
+ ('.$honnin.','.$code.',\''.$situation.'\',\''.$goal.'\',\''.$what.'\',\''.$why.'\',\''.$try.'\',\''.$return1.'\')
65
65
  ');
66
66
  ```
67
67
 
@@ -71,6 +71,7 @@
71
71
  - select 文を代わりに実行して出力してみました。その際は想定動作(すべてのレコードが問題なく出力された)となりました。
72
72
  - XAMPP自体の再インストールを実施しました。エラー内容に変化はありませんでした。
73
73
  - 入れようとしている変数の値をベタ打ち(固定値)でインサートを行ってみましたが、エラー内容に変化はありませんでした。
74
+ - phpMyAdmin上で、実行しても同じエラーが出ます。(#1146 - 表 'portfolio.latest' は存在しません。)
74
75
 
75
76
  ### 補足情報(FW/ツールのバージョンなど)
76
77
 

2

クエリ文字列の出力例追記

2023/02/14 16:47

投稿

tetejiro
tetejiro

スコア15

test CHANGED
File without changes
test CHANGED
@@ -50,7 +50,8 @@
50
50
 
51
51
  ⇒$recをreturn
52
52
  ```
53
-
53
+ 上記の $query を出力した結果は、例えば以下のようになります。
54
+ INSERT INTO question (whose, whom, situation, goal, what, why, try0, return1) VALUES (112,110,'件名','','詳細','','その他','必要')
54
55
 
55
56
  ###### ソースコード②:クエリ文字列を①に渡す部分
56
57
  ```

1

エラー番号追加

2023/02/14 16:31

投稿

tetejiro
tetejiro

スコア15

test CHANGED
@@ -1 +1 @@
1
- MySQLでインサートができません。
1
+ MySQLでインサートができません。SQLSTATE[42S02]
test CHANGED
@@ -29,7 +29,7 @@
29
29
 
30
30
  ["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "42S02" ["file":protected]=> string(57) "C:\xampp\htdocs\portfolio_作業用\new-db\new-select.php" ["line":protected]=> int(20) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(57) "C:\xampp\htdocs\portfolio_作業用\new-db\new-select.php" ["line"]=> int(20) ["function"]=> string(7) "execute" ["class"]=> string(12) "PDOStatement" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [1]=> array(6) { ["file"]=> string(54) "C:\xampp\htdocs\portfolio_作業用\shitumon\hozon.php" ["line"]=> int(76) ["function"]=> string(7) "dbQuery" ["class"]=> string(7) "DbQuery" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(230) " INSERT INTO question (whose, whom, situation, goal, what, why, try0, return1) VALUES (112,110,'件名','','詳細','','その他','必要') " } } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "42S02" [1]=> int(1146) [2]=> string(38) "Table 'portfolio.latest' doesn't exist" } }
31
31
  ```
32
- 'portfolio.latest' doesn't exist" の latest が指定していないのなぜインサートするテーブルに指定されていることになっている、わかりません。
32
+ 'portfolio.latest' doesn't exist" の latest が指定していないの、インサートするテーブルに指定されていることになっているようです。理由が分かりません。
33
33
 
34
34
  ### 該当のソースコード
35
35