2

On the following piece of code, i get the following error:

Couldn't fetch mysqli_stmt

// assign
$title = 'this is the title';
$caption = 'description goes here...';
$filename = '43534b34.jpg';

$thumb = array();
$thumb['basename'] = null;
$thumb['width'] = 0;
$thumb['height'] = 0;

// insert new record in db
$sql = 'INSERT INTO image (title, caption, filename, thumb_filename, thumb_width, thumb_height) VALUES(?, ?, ?, ?, ?, ?)';

$stmt = $conn->stmt_init();

$stmt->prepare($sql);
$stmt->bind_param('ssssii', $title, $caption, $filename, $thumb['basename'], $thumb['width'], $thumb['height']);
$stmt->execute();

if i replace the key in array like $thumb['basename'] = 'test';, then all is ok!

How do i assign the NULL value to my column in the database table?

Marco
  • 2,687
  • 7
  • 45
  • 61

1 Answers1

0

try

$stmt->bind_param('ssssii', $title, $caption, $filename, empty($thumb['basename']) ? NULL : $thumb['basename'] , $thumb['width'], $thumb['height']);
Jerry
  • 3,391
  • 1
  • 19
  • 28