SQL query returning false in PHP

后端 未结 2 1865
感情败类
感情败类 2021-01-27 03:50

I am trying to perform this query in PHP however it keeps returning false. I have tried the query in phpMyAdmin and it works fine so if anyone can spot what is wrong that would

2条回答
  •  再見小時候
    2021-01-27 04:55

    If you are using parameterized queries, then you have to pass the value for the parameter when you execute the prepared query.

    You also have to execute the prepared query. The prepare just passes the query to the database for compilation and optimisation, it does not actually execute the query.

    Also if you get an error in these database access statement, there are functions/methods you should use to show the the actuall error message which are a lot more useful than outputting something you make up yourself like echo "Error creating SQL statement";

    Also the ; is not necessary.

    $stmt = $conn->prepare("SELECT * FROM artist WHERE artID != ?");
    if ( $stmt === false ){
        echo $conn->error;
        exit;
    }
    
    
    $stmt->bindParam('i', $some_variable)
    
    $result = $stmt->execute();
    
    if ( $result === false ) {
        echo $stmt->error;
        exit;
    }
    

提交回复
热议问题