It was a source that had no problems at the time of operation check on other rental servers .. When moved to CPI (shared server)>Call to a member function execute () on boolean in
Will result in an error.

        $pdo->set_charset ('utf8');
        if (! $pdo) {
            throw new PDOException ();

        $stmt = $pdo->prepare ('SELECT count (*) FROM `account` WHERE` id` =: val1 and `pass` =: val2');
        $stmt->execute (array ('val1' =>$user, 'val2' =>$pass));// Here is an error.
        $count = $stmt->fetchColumn ();
        if (! $count) {
                   ------- Discount -------

I don't know what to do.
Someone please tell me more. Thank you.

  • Answer # 1


    Call to a member function execute () on boolean in

    Now we can see that $stmt is boolean.

    If you check prepare, it will return PDOStatement object on success and false on failure, so it should return false in this case.

    If it is

    , you need to check if $pdo correctly returns a PDO object.

    Check with

    var_dump ($pdo);

  • Answer # 2

    PDO :: errorInfo

    If $stmt is false, check $pdo->errorInfo () as shown in Example 1
    You may understand the cause.

  • Answer # 3

    * Please refer to it when using PDO.
    If you leave the connection part as mysqli, the method will change.
    Whichever you use, be sure to read the PHP manual and be confused

    Please refer to the PHP manual.

    Example sentences in the above manual are as follows.

    <? php
    / * Execute a prepared statement with an array of input values ​​* /
    $calories = 150;
    $colour = 'red';
    $sth = $dbh->prepare ('SELECT name, color, calories
        FROM fruit
        WHERE calories<: calories AND color =: colour ');
    $sth->execute (array (': calories' =>$calories, ': colour' =>$colour));

    In the place where ": calories" is set in SQL
    In execute (), the value is set with ": calories" as the key.

    Have you noticed something strange compared to your code?