【问题标题】:I want to assign a NULL value to my column in a database table using the key of an array... how?我想使用数组的键为数据库表中的列分配一个 NULL 值......如何?
【发布时间】:2013-02-06 21:53:21
【问题描述】:

在以下代码中,我收到以下错误:

无法获取 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 值分配给数据库表中的列?

【问题讨论】:

  • 你能粘贴一个关于 thumb_filename 列的 mysql 描述
  • user2023235:根据您提出的问题类型,我检查了是否检查了 assign null 选项......它没有!呃!!!休息时间!谢谢

标签: php mysql arrays


【解决方案1】:

试试

$stmt->bind_param('ssssii', $title, $caption, $filename, empty($thumb['basename']) ? NULL : $thumb['basename'] , $thumb['width'], $thumb['height']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多