I am not trying to use $wpdb->insert, but prepare.
Insert method will have one query string and an array which includes # of data which is not defined but will be defined for each query string keyword.
For example, "address.insert" query string defines a string of query with 3 variables when it process query such as owner_id, address_info, city.
Instead of using $owner_id, ... , $country at the $wpdb->prepare section, I am trying to pass an array holds all of variables listed in below.
Does anyone know if it is doable passing an array for prepare? It wasn't working for me when I tried.
Works
$sql = $wpdb->prepare($this->queryArray[$selectQuery], $owner_id, $address1, $address2, $city, $zip, $country);
Trying to do
$sql = $wpdb->prepare($this->queryArray[$selectQuery], $inputArray);
Here's an example code.
public function Insert($selectQuery, $inputArray)
{
try
{
global $wpdb;
$wpdb->show_errors();
$sql = $wpdb->prepare($this->queryArray[$selectQuery], $owner_id, $address1, $address2, $city, $zip, $country);
$result = $wpdb->query($sql);
return $result;
}
catch(Exception $e)
{
echo $e->getMessage();
return -1;
}
}
Solved: This just works fine.
$sql = $wpdb->prepare($this->queryArray[$selectQuery], $inputArray);