Continue work on insert

This commit is contained in:
sctn4elk 2024-05-03 19:27:12 -05:00
parent 15d72de736
commit e8698e360f
3 changed files with 15 additions and 14 deletions

View File

@ -119,13 +119,13 @@ class CustomerController extends BaseController{
// reads the raw POST data and returns it as a string. // reads the raw POST data and returns it as a string.
$jsonPayload = file_get_contents('php://input'); $jsonPayload = file_get_contents('php://input');
$input = json_decode($jsonPayload, TRUE); $input = json_decode($jsonPayload, TRUE);
//if (! $this->validatePerson($input)) { if (! $this->validatePerson($input)) {
//return $this->unprocessableEntityResponse(); return $this->unprocessableEntityResponse();
//} }
return var_dump($input); //return var_dump($input);
//remove customer_id field so it doesn't break //remove customer_id field so it doesn't break
unset($input['customer_id']); unset($input['customer_id']);
return var_dump($input); //return var_dump($input);
//$modinput = json_encode($input); //$modinput = json_encode($input);
//$newinput = json_decode($modinput, TRUE); //$newinput = json_decode($modinput, TRUE);
$response = $this->customerModel->insertCustomer($input); $response = $this->customerModel->insertCustomer($input);

View File

@ -86,18 +86,19 @@ class CustomerModel extends Database {
return $this->processQuery("SELECT * FROM customer_view WHERE customer_id = ?", ["i", $this->customerId]); return $this->processQuery("SELECT * FROM customer_view WHERE customer_id = ?", ["i", $this->customerId]);
} }
public function insertCustomer($jsonPayLoad) public function insertCustomer($inputModel)
{ {
//return var_dump($jsonPayLoad); //return var_dump($jsonPayLoad);
$keys = array_keys($jsonPayLoad); $keys = array_keys($inputModel);
$n = count($keys); $n = count($keys);
$query .= "CALL insert_new_customer_proc ('" . $jsonPayLoad[$keys[0]] . "', "; $query .= "CALL insert_new_customer_proc (";
for($i = 1; $i < $n-1; $i++) { for($i = 0; $i < $n-1; $i++) {
$query .= "'" . $jsonPayLoad[$keys[$i]] . "', "; $query .= "'" . $inputModel[$keys[$i]] . "', ";
} }
$query .= $jsonPayLoad[$keys[$i]] . ")"; $query .= $inputModel[$keys[$i]] . ")";
return var_dump($query); //return var_dump($query);
$rowCount = $this->processStatement($query); $rowCount = $this->processStatement($query);
return $rowCount; return $rowCount;
} }

View File

@ -65,10 +65,10 @@ class Database {
if($stmt === false) { if($stmt === false) {
throw New Exception("Unable to prepare the statement: " . $query); throw New Exception("Unable to prepare the statement: " . $query);
} }
//return var_dump($query);
$result = $stmt->execute(); $result = $stmt->execute();
if($result === false) { if($result === false) {
throw New Exception("Unable to execute the statement."); throw New Exception("Unable to execute the statement: " . $query);
} }
//$rowCount = $this->executeStatement($stmt); //$rowCount = $this->executeStatement($stmt);