update page now

Voting

The Note You're Voting On

cdtreeks at gmail dot com
11 years ago
When executing a prepared MySQL, by default if there's an error then you'll simply get FALSE returned from your call to prepare().

To get the full MySQL error back create a statement object before preparing your query as such:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$city = "Amersfoort";

/* create a prepared statement */
$statement = $mysqli->stmt_init();
if ($statement->prepare("SELECT District FROM City WHERE Name=?")) {

    /* bind parameters for marker(s) */
    $statement->bind_param("s", $city);

    /* execute query */
    if (!$statement->execute()) {
        trigger_error('Error executing MySQL query: ' . $statement->error);
    }

    /* bind result variables */
    $statement->bind_result($district);

    /* fetch value */
    $statement->fetch();

    printf("%s is in district %s\n", $city, $district);

    /* close statement */
    $statement->close();
}

/* close connection */
$mysqli->close();
?>

<< Back to user notes page

To Top