12

I have a complex query that gets executed like this:

if ($stmt = $dbi->prepare($pt_query)) {   
        $stmt->bind_param('ssssssssi', $snome,$scognome,$ssocieta,$svia,$slocalita,$sprovincia,$scap,$stelefono,$sfax,$uid);
        $stmt->execute();           
        echo $dbi->error;
        $stmt->close();

    } else {
        printf("Error -> %s\n", $dbi->error);
    }

This thing is failing without any error, it simply doesn't update the database. Since there is a ton of data that gets treated before this thing I would like to know if there is any way to show the actual query that mysqli is executing in order to understand where the problem is.

Thank you.

0plus1
  • 4,475
  • 12
  • 47
  • 89
  • 1
    Doesn't seem to be possible. Dupe: http://stackoverflow.com/questions/962986/how-to-echo-a-mysqli-prepared-statement – Pekka Apr 22 '10 at 14:33

4 Answers4

10

If your statement is failing, you should check $stmt->error (as opposed to $dbi->error). As far as getting the actual text of the query: it's not possible. When using prepared statements, the library is using a special protocol that doesn't generate an actual query string for each ->execute() call.

awgy
  • 16,596
  • 4
  • 25
  • 18
5

You could turn on logging on the MySQL DB itself, ie. add a log=logfile line to my.ini.

Refer to the MySQL documentation for more information if needed.

wimvds
  • 12,790
  • 2
  • 41
  • 42
1

Here's a tool I found that may help MySQLi Prepare Statement checker

Mike S.
  • 2,048
  • 1
  • 32
  • 55
0

Based on the PHP mysql website there is no actual way of doing it. But you may try this function as it gives you errors in your query.

Jonathan Czitkovics
  • 1,642
  • 11
  • 11