1

In this block, $stmt returns not false as expects, $bind is true, but when I get to $stmt->execute(), it exits, and returns neither true nor false. The only time I can get false out of it, is if I use some variable in the argument for execute per it's documentation, but I've never used an argument in an execute call, and I can't find an example of anyone else using one except in procedural prepared statements. I don't know if I'm missing something. Anyone have any ideas?

$stmt = $mysqli->prepare("SELECT ... FROM `table` WHERE `tid` = ?");

if ($stmt !== FALSE) {
    echo 'Statement was true.';
    $bind = $stmt->bind_param('s', $this->tid);
    echo 'after bind';
    if ($bind)
        echo 'bind was good ';
    else
        echo 'bind was bad';
    $exec = $stmt->execute();
    if ($exec)
        echo 'exec was good';
    else
        echo 'exec was bad';
    echo 'after execute';
    // etc.
} else {
 // rest of code
}

@tntu's accepted answer and following comments got me on the right track for solving this problem. [link]http://stackoverflow.com/questions/5580039/fatal-error-uncaught-exception-mysqli-sql-exception-with-message-no-index-us

MySQL can do a lot of error reporting, and I had set mysqli_report(MYSQLI_REPORT_ALL) set earlier in the stack and in the function in question in order to figure out some other problems. At any rate, setting mysqli_report(MYSQLI_REPORT_OFF) enabled the execute to run as intended, and not bog php down with warnings, and errors.

Matt Walther
  • 383
  • 5
  • 12

1 Answers1

1
$bind = $stmt->bind_param('s', $this->tid);

s stands for string

Change it to i and it should work.

Also see about doing some error management. mysqli_erro, mysqli_errno

Something like this:

if ($mysqli->errno) { logging("ERRO: ".$mysqli->error . "( " . $mysqli->errno . " )"); }
transilvlad
  • 13,974
  • 13
  • 45
  • 80
  • It did not. The problem persists. – Matt Walther Oct 18 '12 at 07:50
  • Stupid question but are you sure you are actually connected to MySQL? There is error handling dedicated for connection errors. – transilvlad Oct 18 '12 at 07:53
  • Add this at the top of your code: ini_set("log_errors", 1); ini_set("error_log", __DIR__ . "errors.log"); – transilvlad Oct 18 '12 at 07:54
  • Yeah, I check the connection on entering each function. It's redundant, and less efficient, but I've had the issue before. I think prepare would also pass false to me, if I wasn't connected. – Matt Walther Oct 18 '12 at 07:54
  • [18-Oct-2012 08:56:28] PHP Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement SELECT ... FROM `table` WHERE `tid` = ?' in /home/www/htdocs/include/Audit.class.php:94 Then it gave me a stack trace. – Matt Walther Oct 18 '12 at 08:07
  • This lead me to here [link]http://stackoverflow.com/questions/5580039/fatal-error-uncaught-exception-mysqli-sql-exception-with-message-no-index-us Which fixed the issue. Thanks for helping me sniff it out @tntu – Matt Walther Oct 18 '12 at 08:17
  • When you have a problem and something does not work make sure you do error handling and capture so you can see what is going on. – transilvlad Oct 18 '12 at 09:09