mysqli bind_param中的NULL类型是什么?

 shadow 发布于 2023-02-06 10:22

我试图将params绑定到INSERT INTO MySQLi预处理语句,如果该变量存在,否则插入null.然后我知道

type    variable
i   corresponding variable has type integer
d   corresponding variable has type double
s   corresponding variable has type string
b   corresponding variable is a blob and will be sent in packets

但是当我插入一个变量= null时,我如何定义变量的类型?或者我应该定义类型''?

1 个回答
  • 您不需要将null转换为特定的数据类型 - Mysqli将处理传递给任何接受的数据类型的空值,因此只要使用每个字段在传递非空值时所具有的类型.

    $intVar = null;
    $doubleVar = null;
    $stringVar = null;
    $blobVar = null;
    
    $insert_data->bind_param('idsb', $intVar, $doubleVar, $stringVar, $blobVar);
    

    所有这些都是有效的,并将被Mysqli接受.

    2023-02-06 10:23 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有