Skip to content

Commit e4d16e7

Browse files
author
peejeh
committed
*** empty log message ***
1 parent e22e778 commit e4d16e7

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

phprestsql.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[settings]
2-
baseURL = "/PHPRestSQL/"
2+
baseURL = "/PHPRestSQL/demo/?"
33

44
[database]
55
type = "mysql"

phprestsql.php

+30-8
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function post() {
305305
$this->badRequest();
306306
}
307307
} else {
308-
$this->badRequest();
308+
$this->internalServerError();
309309
}
310310
} else {
311311
$this->badRequest();
@@ -347,7 +347,7 @@ function post() {
347347
$this->badRequest();
348348
}
349349
} else {
350-
$this->badRequest();
350+
$this->internalServerError();
351351
}
352352
} else {
353353
$this->lengthRequired();
@@ -370,14 +370,29 @@ function put() {
370370
$values = join('", "', $this->uid).'", "'.join('", "', $pairs);
371371
$names = join('`, `', $primary).'`, `'.join('`, `', array_keys($pairs));
372372
$resource = $this->db->insertRow($this->table, $names, $values);
373-
if ($resource) {
374-
if ($this->db->numAffected() > 0) {
375-
$this->created();
373+
if ($resource && $this->db->numAffected() > 0) {
374+
$this->created();
375+
} else {
376+
$values = '';
377+
foreach ($pairs as $column => $data) {
378+
$values .= '`'.$column.'` = "'.$this->db->escape($data).'", ';
379+
}
380+
$values = substr($values, 0, -2);
381+
$where = '';
382+
foreach($primary as $key => $pri) {
383+
$where .= $pri.' = '.$this->uid[$key].' AND ';
384+
}
385+
$where = substr($where, 0, -5);
386+
$resource = $this->db->updateRow($this->table, $values, $where);
387+
if ($resource) {
388+
if ($this->db->numAffected() > 0) {
389+
$this->noContent();
390+
} else {
391+
$this->badRequest();
392+
}
376393
} else {
377-
$this->methodNotAllowed('GET, HEAD, DELETE, POST');
394+
$this->internalServerError();
378395
}
379-
} else {
380-
$this->methodNotAllowed('GET, HEAD, DELETE, POST');
381396
}
382397
} else {
383398
$this->badRequest();
@@ -539,6 +554,13 @@ function lengthRequired() {
539554
header('HTTP/1.0 411 Length Required');
540555
}
541556

557+
/**
558+
* Send a HTTP 500 response header.
559+
*/
560+
function internalServerError() {
561+
header('HTTP/1.0 500 Internal Server Error');
562+
}
563+
542564
}
543565

544566
?>

0 commit comments

Comments
 (0)