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

前端 未结 2 714
轻奢々
轻奢々 2021-01-27 15:54


        
相关标签:
2条回答
  • 2021-01-27 16:24

    You are combining Object Oriented style with the normal procedural mysqli style. On line 5 you use.

    mysqli_connect()
    

    and on line 12 you use.

    $connection->prepare()
    

    This will not work, if you'd change $connection to, object oriented style like you do with your prepare statement, it will work.

    $connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname'])
    

    More information can be found here http://php.net/manual/en/mysqli.prepare.php

    0 讨论(0)
  • 2021-01-27 16:44

    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
    ?>
    

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

    0 讨论(0)
提交回复
热议问题