致命错误:在布尔值上调用成员函数execute() [英] Fatal error: Call to a member function execute() on boolean

查看:90
本文介绍了致命错误:在布尔值上调用成员函数execute()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
    session_start();
    $config = parse_ini_file('../database_config.ini'); 
    //Create Database connection
    $connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);

    if ($connection->connect_error) {
        die('Could not connect to db: ' . mysql_error());
    }


    $stmt = $connection->prepare("INSERT INTO report (reportID, userID, description, address, postalcode, latitude, longitude) 
    VALUES(0, 007, 'Major fire', 'Jurong Point', 640724, 1.640724, 103.640724)");

        $stmt->execute();
        echo "Error:\n";
        print_r($stmt->error_list);
        $stmt->close();

        $connection->close();
?>

错误:Fatal error: Call to a member function execute() on boolean

为什么我的prepare语句失败?

Why does my prepare statement fail?

report表的结构

推荐答案

您需要按以下方式进行:-

You need to do it in following manner:-

<?php
    session_start();
    $config = parse_ini_file('../database_config.ini'); 
    //Create Database connection
    $connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);

    if (mysqli_connect_errno()) { // check the change of if condition
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    $stmt = mysqli_prepare($connection,"INSERT INTO report (reportID, userID, description, address, postalcode, latitude, longitude) VALUES(0, 007, 'Major fire', 'Jurong Point', 640724, 1.640724, 103.640724)"); // check the change in query code

    mysqli_stmt_execute($stmt); // check the change in execution code
    echo "Error:\n";
    print_r(mysqli_error($connection)); // check the change in error getting code
    mysqli_stmt_close($stmt);// check the change in statement closing code
    mysqli_close($connection); // check the change in db connection closing code
?>

有关更多知识,请参见链接及其示例:- http://php.net/手册/en/mysqli.prepare.php

For more knowledge refer link and it's example:- http://php.net/manual/en/mysqli.prepare.php

这篇关于致命错误:在布尔值上调用成员函数execute()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆