donglv5269 2019-05-24 02:19
浏览 175
已采纳

致命错误:未捕获错误:调用未定义函数mysql_close()

I'm learning about MySQL prepare statement and when I run the following code, I get the PHP Fatal error: Uncaught Error: Call to undefined function mysql_close(). The output is correct and I just can't figure out why such an error occurs. Thanks for your time!

$conn3 = new mysqli(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME);

$event_type = $jarray['event_type'];
$key = "submission";

$search = $conn3->prepare("SELECT * FROM metadb USE INDEX(field_id) WHERE event_type = ? AND event_field = ?");
$search->bind_param('ss', $event_type, $key); 
$search->execute();
$search->store_result();

echo $search->num_rows;

mysql_close($conn3);
  • 写回答

1条回答 默认 最新

  • dryl34156 2019-05-24 02:22
    关注

    Use $conn3->close(); instead of mysql_close($conn3);

    You are using mysqli to open connection and then trying to close connection using mysql.

    Suggestion : You are mixing mysqliobject oriented and procedural in your code I will suggest you to stick with one(preferably Object Oriented). I will also suggest you to start using PDO instead of mysqli. reason explained here

    For more detailed information about mysqli you can refer this documentation.

    For more detailed information about PDO you can refer this documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥80 关于海信电视聚好看安装应用的问题
    • ¥15 vue引入sdk后的回调问题
    • ¥15 求一个智能家居控制的代码
    • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
    • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信
    • ¥15 使用QT实现can通信