2

次のコードでは、次のエラーが発生します。

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();

のように配列のキーを置き換えると $thumb['basename'] = 'test';、すべて問題ありません。

データベース テーブルの列に NULL 値を割り当てるにはどうすればよいですか?

4

1 に答える 1

0

試す

$stmt->bind_param('ssssii', $title, $caption, $filename, empty($thumb['basename']) ? NULL : $thumb['basename'] , $thumb['width'], $thumb['height']);
于 2013-02-06T22:06:51.260 に答える