|
@@ -69,7 +69,7 @@ class MySQL_CRUD_API extends REST_CRUD_API {
|
69
|
69
|
return "'".mysqli_real_escape_string($db,$param)."'";
|
70
|
70
|
}, $sql);
|
71
|
71
|
//echo "\n$sql\n";
|
72
|
|
- return mysqli_query($db,$sql);
|
|
72
|
+ return mysqli_query($db,$sql);
|
73
|
73
|
}
|
74
|
74
|
|
75
|
75
|
protected function fetch_assoc($result) {
|
|
@@ -404,12 +404,7 @@ class MsSQL_CRUD_API extends REST_CRUD_API {
|
404
|
404
|
if (strtoupper(substr($sql,0,6))=='INSERT') {
|
405
|
405
|
$sql .= ';SELECT SCOPE_IDENTITY()';
|
406
|
406
|
}
|
407
|
|
- $result = sqlsrv_query($db,$sql,$args);
|
408
|
|
- if ($result===false) {
|
409
|
|
- $errors = sqlsrv_errors();
|
410
|
|
- $this->exitWith409(compact('sql','args','errors'));
|
411
|
|
- }
|
412
|
|
- return $result;
|
|
407
|
+ return sqlsrv_query($db,$sql,$args)?:null;
|
413
|
408
|
}
|
414
|
409
|
|
415
|
410
|
protected function fetch_assoc($result) {
|
|
@@ -524,24 +519,12 @@ class REST_CRUD_API {
|
524
|
519
|
}
|
525
|
520
|
|
526
|
521
|
protected function applyInputSanitizer($callback,$action,$database,$table,&$input) {
|
527
|
|
- if (is_array($input)) {
|
528
|
|
- foreach (array_keys($input) as $i) {
|
529
|
|
- $this->applyInputSanitizer($callback,$action,$database,$table,$input[$i]);
|
530
|
|
- }
|
531
|
|
- return;
|
532
|
|
- }
|
533
|
522
|
if (is_callable($callback,true)) foreach ((array)$input as $key=>$value) {
|
534
|
523
|
$input->$key = $callback($action,$database,$table,$key,$value);
|
535
|
524
|
}
|
536
|
525
|
}
|
537
|
526
|
|
538
|
527
|
protected function applyInputValidator($callback,$action,$database,$table,&$input) {
|
539
|
|
- if (is_array($input)) {
|
540
|
|
- foreach (array_keys($input) as $i) {
|
541
|
|
- $this->applyInputValidator($callback,$action,$database,$table,$input[$i]);
|
542
|
|
- }
|
543
|
|
- return;
|
544
|
|
- }
|
545
|
528
|
$errors = array();
|
546
|
529
|
if (is_callable($callback,true)) foreach ((array)$input as $key=>$value) {
|
547
|
530
|
$error = $callback($action,$database,$table,$key,$value);
|
|
@@ -603,7 +586,7 @@ class REST_CRUD_API {
|
603
|
586
|
protected function exitWith422($object) {
|
604
|
587
|
if (isset($_SERVER['REQUEST_METHOD'])) {
|
605
|
588
|
header('Content-Type:',true,422);
|
606
|
|
- die('Unprocessable Entity');
|
|
589
|
+ die(json_encode($object));
|
607
|
590
|
} else {
|
608
|
591
|
throw new \Exception(json_encode($object));
|
609
|
592
|
}
|
|
@@ -777,7 +760,7 @@ class REST_CRUD_API {
|
777
|
760
|
$input = (object)array();
|
778
|
761
|
$data = trim(file_get_contents($post));
|
779
|
762
|
if (strlen($data)>0) {
|
780
|
|
- if ($data[0]=='{' || $data[0]=='[') {
|
|
763
|
+ if ($data[0]=='{') {
|
781
|
764
|
$input = json_decode($data);
|
782
|
765
|
} else {
|
783
|
766
|
parse_str($data, $input);
|
|
@@ -809,12 +792,6 @@ class REST_CRUD_API {
|
809
|
792
|
}
|
810
|
793
|
|
811
|
794
|
protected function limitInputFields($input,$fields) {
|
812
|
|
- if (is_array($input)) {
|
813
|
|
- foreach (array_keys($input) as $i) {
|
814
|
|
- $input[$i] = $this->limitInputFields($input[$i],$fields);
|
815
|
|
- }
|
816
|
|
- return $input;
|
817
|
|
- }
|
818
|
795
|
foreach (array_keys((array)$input) as $key) {
|
819
|
796
|
if (!isset($fields[$key])) {
|
820
|
797
|
unset($input->$key);
|
|
@@ -824,12 +801,6 @@ class REST_CRUD_API {
|
824
|
801
|
}
|
825
|
802
|
|
826
|
803
|
protected function convertBinary($input,$fields) {
|
827
|
|
- if (is_array($input)) {
|
828
|
|
- foreach (array_keys($input) as $i) {
|
829
|
|
- $input[$i] = $this->convertBinary($input[$i],$fields);
|
830
|
|
- }
|
831
|
|
- return $input;
|
832
|
|
- }
|
833
|
804
|
foreach ($fields as $key=>$field) {
|
834
|
805
|
if (isset($input->$key) && $input->$key && $this->is_binary_type($field)) {
|
835
|
806
|
$data = $input->$key;
|
|
@@ -1045,15 +1016,7 @@ class REST_CRUD_API {
|
1045
|
1016
|
extract($parameters);
|
1046
|
1017
|
if (!$input) $this->exitWith404('input');
|
1047
|
1018
|
$this->startOutput($callback);
|
1048
|
|
- if (!is_array($input)) {
|
1049
|
|
- echo json_encode($this->createObject($input,$table,$db));
|
1050
|
|
- } else {
|
1051
|
|
- $result = array();
|
1052
|
|
- foreach ($input as $i) {
|
1053
|
|
- $result[] = $this->createObject($i,$table,$db);
|
1054
|
|
- }
|
1055
|
|
- echo json_encode($result);
|
1056
|
|
- }
|
|
1019
|
+ echo json_encode($this->createObject($input,$table,$db));
|
1057
|
1020
|
$this->endOutput($callback);
|
1058
|
1021
|
}
|
1059
|
1022
|
|