Answer the question
In order to leave comments, you need to log in
How to defeat NULL when compiling a query in the database?
$valueString = join ( "','", $itemValues );
replaces null with ""
$valueString = join ( "','", $itemValues );
$valueString = "('" . $valueString . "'),";
$values = "\n" . $valueString;
if ($values != "") {
$data_string = "INSERT INTO `$tableName` (`$items`) VALUES" . rtrim ( $values, "," ) . ";;;" . PHP_EOL;
if ($this->fp)
fwrite ( $this->fp, $data_string );
}
Answer the question
In order to leave comments, you need to log in
Accordingly, figure out how to correctly represent NULL in values with NULL. This use of the join function will obviously have to be abandoned.
And it is better not to be perverted, and use pdo prepared statements, which null can be passed regularly.
$valueString = '';
foreach($itemValues as $val) {
$valueString = is_null($val) ? 'null,' : sprintf('"%s",', $val);
}
$valueString = rtrim($valueString, ',');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question