0


I'm using a prepared statement that fails and I don't know why (no error is returned)
Here's my code:

$stmt = $db->prepare("SELECT id, temps, nom, classes FROM profs WHERE matiere = ? AND pass = 0");
if ( false===$stmt ) {
    die('prepare() failed: ('.$db->errno.')' . htmlspecialchars($db->error));
}
$rc = $stmt->bind_param("s", $mat);
if ( false===$rc ) {
    die('bind_param() failed: ('.$db->errno.')' . htmlspecialchars($stmt->error));
}
$rc = $stmt->execute();
if ( false===$rc ) {
    die('execute() failed: ('.$db->errno.')' . htmlspecialchars($stmt->error));
}

This returns only: "prepare() failed: (0)"
Where's the problem?

iguider
  • 721
  • 1
  • 12
  • 25

1 Answers1

0

SELECT id, temps, nom, classes FROM profs WHERE matiere = ? AND pass = 0

Is this query valid? Does the profs table exist, and do the columns (id, temps, nom, classes, matiere, pass) exist (and spelt correctly!)

Farkie
  • 3,307
  • 2
  • 22
  • 33
  • infact, just `var_dump($db);` see what comes out? – Farkie May 25 '13 at 11:05
  • Here's what I get from var_dump($db); : `"object(mysqli)#1 (18) {\n [\"affected_rows\"]=>\n int(-1)\n [\"client_info\"]=>\n string(6) \"5.5.29\"\n [\"client_version\"]=>\n int(50529)\n [\"connect_errno\"]=>\n int(0)\n [\"connect_error\"]=>\n NULL\n [\"errno\"]=>\n int(0)\n [\"error\"]=>\n string(0) \"\"\n [\"field_count\"]=>\n int(6)\n [\"host_info\"]=>\n string(25) \"Localhost via UNIX socket\"\n [\"info\"]=>\n NULL\n [\"insert_id\"]=>\n int(0)\n [\"server_info\"]=>\n string(23) \"5.5.31-0ubuntu0.12.04.1\"\n [\"server_version\"]=>\n int(50531)\n` – iguider May 25 '13 at 11:10
  • Countinue: `[\"stat\"]=>\n string(136) \"Uptime: 11142 Threads: 1 Questions: 848 Slow queries: 0 Opens: 612 Flush tables: 1 Open tables: 152 Queries per second avg: 0.076\"\n [\"sqlstate\"]=>\n string(5) \"00000\"\n [\"protocol_version\"]=>\n int(10)\n [\"thread_id\"]=>\n int(141)\n [\"warning_count\"]=>\n int(0)\n}\n` – iguider May 25 '13 at 11:12
  • Not sure why you -1'd me, but nevermind. That indicates you are definitely connected, but I can't what is wrong if that is your exact code, and you put the var_dump($db) directly after the $stmt line... – Farkie May 25 '13 at 11:23
  • I'm not the one who -1'd you.. :/ So there's no solution? – iguider May 25 '13 at 12:03
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30617/discussion-between-ider-aghbal-and-farkie) – iguider May 25 '13 at 13:25
  • 1
    Hi, I just got the same issue trying to prepare an `INSERT` query ... For those who do not have any idea where to look at, [THIS](http://stackoverflow.com/questions/1219809/mysqli-prepare-statement-returning-false-but-why) is how I solved my problem ! – Stphane Jan 30 '14 at 08:05