質問編集履歴

1

db_hostの削除,else文の追加(ifがselectクエリーが失敗),$sqlと$resultの定義の変更,日本語設定の変更,catchの前の}の追加

2021/12/25 03:13

投稿

zzz08759310
zzz08759310

スコア0

test CHANGED
File without changes
test CHANGED
@@ -22,33 +22,73 @@
22
22
 
23
23
  $db_pass ='パスワード';
24
24
 
25
+
26
+
27
+
28
+
25
- $db_host ='ホスト名';
29
+ $baba = filter_input(INPUT_POST, 'baba');
30
+
31
+ $kyori1 = filter_input(INPUT_POST, 'kyori1');
32
+
33
+ $kyori2 = filter_input(INPUT_POST, 'kyori2');
34
+
35
+ $kyaku1 = filter_input(INPUT_POST, 'kyaku1');
36
+
37
+ $kyaku2 = filter_input(INPUT_POST, 'kyaku2');
38
+
39
+ $ikusei = filter_input(INPUT_POST, 'ikusei');
40
+
41
+
42
+
43
+ $message = array();
44
+
45
+
46
+
47
+ $link = mysqli_connect($db_ipaddress, $db_id, $db_pass);
48
+
49
+ if ( ! $link ) {
50
+
51
+ die('接続失敗'.mysql_error() );
52
+
53
+
54
+
55
+ }
56
+
57
+ else {
58
+
59
+ print "mysql 接続完了<br>";
60
+
61
+
62
+
63
+ }
26
64
 
27
65
  $usedatabase ='db名';
28
66
 
29
- $baba = filter_input(INPUT_POST, 'baba');
30
-
31
- $kyori1 = filter_input(INPUT_POST, 'kyori1');
32
-
33
- $kyori2 = filter_input(INPUT_POST, 'kyori2');
34
-
35
- $kyaku1 = filter_input(INPUT_POST, 'kyaku1');
36
-
37
- $kyaku2 = filter_input(INPUT_POST, 'kyaku2');
38
-
39
- $ikusei = filter_input(INPUT_POST, 'ikusei');
40
-
41
-
42
-
43
- $message = array();
44
-
45
-
46
-
47
- $link = mysqli_connect($db_ipaddress, $db_id, $db_pass ,$db_host);
67
+ $db_selected = mysqli_select_db($link,$usedatabase);
48
-
68
+
49
- if ( ! $link ) {
69
+ if ( ! $db_selected ) {
50
-
70
+
51
- die('接続失敗'.mysql_error() );
71
+ die('データベース選択失敗'.mysql_error() );
72
+
73
+ }
74
+
75
+ else {
76
+
77
+ print "データベース選択完了<br>";
78
+
79
+ }
80
+
81
+ mysqli_set_charset($link,'utf-8');
82
+
83
+ $sql = 'select * from uma_musume';
84
+
85
+ $result = mysqli_query($link,$sql);
86
+
87
+
88
+
89
+ if ( ! $result ) {
90
+
91
+ die('selectクエリーが失敗'.mysql_error() );
52
92
 
53
93
 
54
94
 
@@ -56,39 +96,15 @@
56
96
 
57
97
  else {
58
98
 
59
- print "mysql 接続完了<br>";
99
+ print "sql文が無事に稼働<br>";
100
+
60
-
101
+ print"データ取得完了<br>";
61
-
62
-
102
+
63
- }
103
+ }
64
-
65
- $db_selected = mysqli_select_db($link,$usedatabase);
104
+
66
-
67
- if ( ! $db_selected ) {
105
+
68
-
69
- die('データベース選択失敗'.mysql_error() );
106
+
70
-
71
- }
107
+
72
-
73
- else {
74
-
75
- print "データベース選択完了<br>";
76
-
77
- }
78
-
79
- mysqli_set_charset('utf-8');
80
-
81
- mysqli_set_charset($link,'utf-8');
82
-
83
- $result = mysqli_query('select * from uma_musume');
84
-
85
- if ( ! $result ) {
86
-
87
- die('selectクエリーが失敗'.mysql_error() );
88
-
89
-
90
-
91
- }
92
108
 
93
109
  try {
94
110
 
@@ -112,6 +128,8 @@
112
128
 
113
129
  $dbh = null;
114
130
 
131
+ }
132
+
115
133
  catch (PDOException $e) { //ここからエラー
116
134
 
117
135
  $message = '<p>DATABASE ERROR</p>';