I have a database table like this and want to update some values
customerNumber (INT)
company (VARCHAR)
contactPerson (VARCHAR)
phoneNumber (VARCHAR)
username (VARCHAR)
password (VARCHAR)
email (VARCHAR)
create_at (TIMESTAMP)
This is my update fuction
public function updateUser()
{
//UPDATE datadump SET content=? WHERE id=?
$query = 'UPDATE customer SET (company, contactPerson, phoneNumber, email) VALUES (?, ?, ?, ?) WHERE customerNumver = ?';
$paramType = 'ssssi';
$ParamValue = array(
$_POST["CustomerCompany"],
$_POST["CustomercontactPerson"],
$_POST["CustomerphoneNumber"],
$_POST["CustomerEmail"],
$_POST["customerNumber"]
);
$this->ds->insert($query, $paramType, $ParamValue);
}
I'am calling insert
because what I read should act as an update. Or does it not?
public function insert($query, $paramType, $paramArray)
{
$stmt = $this->conn->prepare($query);
$this->bindQueryParams($stmt, $paramType, $paramArray);
$stmt->execute();
$insertId = $stmt->insert_id;
return $insertId;
}
I get the error in the log
thrown in /opt/lampp/htdocs/lib/DataSource.php on line 158 [23-Feb-2021 10:38:57 Europe/Berlin] PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, first array member is not a valid class name or object in /opt/lampp/htdocs/lib/DataSource.php:158 Stack trace: #0 /opt/lampp/htdocs/lib/DataSource.php(158): call_user_func_array(Array, Array) #1 /opt/lampp/htdocs/lib/DataSource.php(118): DataSource->bindQueryParams(false, 'ssssi', Array) #2 /opt/lampp/htdocs/Model/Customer.php(293): DataSource->insert('UPDATE customer...', 'ssssi', Array) #3 /opt/lampp/htdocs/modify-address.php(28): Customer->updateUser() #4 {main} thrown in /opt/lampp/htdocs/lib/DataSource.php on line 158
This is line 158 in DataSource.php
public function bindQueryParams($stmt, $paramType, $paramArray = array())
{
$paramValueReference[] = & $paramType;
for ($i = 0; $i < count($paramArray); $i ++) {
$paramValueReference[] = & $paramArray[$i];
}
call_user_func_array(array(
$stmt, //this is line 158
'bind_param'
), $paramValueReference);
}
Is the problem that I do not have all the fields in my database in my prepere statement? I do not want to update all fields, how do I do or can I do as I do?
Does it work to use my insert function or how should I modify it?