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

質問編集履歴

3

修正

2017/04/13 09:01

投稿

coko1
coko1

スコア276

title CHANGED
File without changes
body CHANGED
@@ -7,90 +7,4 @@
7
7
  ,SUBSTRING(zipcd,4,7) as zipcd_2
8
8
  from
9
9
  test_table
10
- ```
11
-
12
- ```php
13
- <?php /* js to sql */
14
-
15
- include(dirname(__FILE__).'/import.php');
16
-
17
- $inputData = json_decode($_POST['inputData']);
18
-
19
- //select結果格納用配列初期化
20
- $data = array();
21
- for($i=0;$i<count($inputData);$i++){
22
- $record = $inputData[$i];
23
- $rows = array();
24
- //sqlの情報を取得
25
- $sqlfile = array_shift($record);
26
- $sqlpath = get_sql_base_path(dirname(__FILE__)).$sqlfile;
27
- $sql = @file_get_contents($sqlpath);
28
-
29
- //sqlの内容がselectであるか
30
- if( mb_strtolower( substr($sql, 0, 6) ) !== 'select'){
31
- header('HTTP/1.0 403 Forbidden');
32
- exit;
33
- }
34
-
35
- if(!select($sql, $rows, $record)){
36
- //select失敗
37
- header('Content-Type: application/json');
38
- echo json_encode( false );
39
- exit;
40
- }
41
-
42
- array_push($data,$rows);
43
- }
44
- header('Content-Type: application/json');
45
- echo json_encode( $data );
46
- exit;
47
-
48
- ?>
49
- ```
50
-
51
- ```php
52
- function select($sql, &$data, $params){
53
- $data = array(); //データ配列初期化
54
- $mysqli = get_connection();
55
- if(is_null($mysqli)){
56
- return false;
57
- }
58
- if(!is_array($params))$params = array();
59
-
60
- if(count($params)>0){
61
- //パラメータが1つ以上存在する場合
62
- $stmt = mysqli_stmt_init($mysqli);
63
- if(!mysqli_stmt_prepare($stmt, $sql)){
64
- //SQLステートメント実行準備失敗
65
- return false;
66
- }
67
- $stmt_params = array($stmt, '');
68
- foreach($params as $idx => $value){
69
- if(is_int($value))$stmt_params[1] .= 'i';
70
- else if(is_float($value))$stmt_params[1] .= 'd';
71
- else if(is_string($value))$stmt_params[1] .= 's';
72
- //else return false;
73
- $stmt_params[] = &$params[$idx];
74
- }
75
- call_user_func_array( "mysqli_stmt_bind_param" ,$stmt_params );
76
- if(!mysqli_stmt_execute($stmt)){
77
- //SQLステートメント実行失敗
78
- return false;
79
- }
80
- $result = mysqli_stmt_get_result($stmt);
81
- }else{
82
- //上記以外の場合
83
- $result = mysqli_query($mysqli, $sql, MYSQLI_STORE_RESULT );
84
- }
85
-
86
- while ($row = mysqli_fetch_assoc($result)){
87
- //結果を処理
88
- array_push($data, $row);
89
- }
90
-
91
- mysqli_free_result($result);
92
- mysqli_close($mysqli);
93
-
94
- return true;
95
- }
96
10
  ```

2

修正

2017/04/13 09:01

投稿

coko1
coko1

スコア276

title CHANGED
File without changes
body CHANGED
@@ -10,6 +10,45 @@
10
10
  ```
11
11
 
12
12
  ```php
13
+ <?php /* js to sql */
14
+
15
+ include(dirname(__FILE__).'/import.php');
16
+
17
+ $inputData = json_decode($_POST['inputData']);
18
+
19
+ //select結果格納用配列初期化
20
+ $data = array();
21
+ for($i=0;$i<count($inputData);$i++){
22
+ $record = $inputData[$i];
23
+ $rows = array();
24
+ //sqlの情報を取得
25
+ $sqlfile = array_shift($record);
26
+ $sqlpath = get_sql_base_path(dirname(__FILE__)).$sqlfile;
27
+ $sql = @file_get_contents($sqlpath);
28
+
29
+ //sqlの内容がselectであるか
30
+ if( mb_strtolower( substr($sql, 0, 6) ) !== 'select'){
31
+ header('HTTP/1.0 403 Forbidden');
32
+ exit;
33
+ }
34
+
35
+ if(!select($sql, $rows, $record)){
36
+ //select失敗
37
+ header('Content-Type: application/json');
38
+ echo json_encode( false );
39
+ exit;
40
+ }
41
+
42
+ array_push($data,$rows);
43
+ }
44
+ header('Content-Type: application/json');
45
+ echo json_encode( $data );
46
+ exit;
47
+
48
+ ?>
49
+ ```
50
+
51
+ ```php
13
52
  function select($sql, &$data, $params){
14
53
  $data = array(); //データ配列初期化
15
54
  $mysqli = get_connection();

1

修正

2017/02/21 08:52

投稿

coko1
coko1

スコア276

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,5 @@
1
1
  タイトル通りの質問になるのですが、郵便番号を切り分けて取得するために、以下のようなSQLを記述しているのですが、取得結果で切り分けた状態で郵便番号が取得できません。なぜだかわかる方お力を貸していただけないでしょうか?
2
+ ※seelect事態は正常に行なわれています。
2
3
 
3
4
  ```sql
4
5
  select