Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to print the actual query that mysqli->execute() makes?

Tags:

php

mysqli

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.

like image 869
0plus1 Avatar asked Apr 22 '10 14:04

0plus1


People also ask

How do I find MySQLi query results?

The fetch_row() / mysqli_fetch_row() function fetches one row from a result-set and returns it as an enumerated array.

What is execute () in PHP?

Execute: At a later time, the application binds the values to the parameters, and the database executes the statement. The application may execute the statement as many times as it wants with different values.

Which MySQLi function is used to execute any query against the database?

The query() / mysqli_query() function performs a query against a database.

What is the output of mysqli_query?

Mysqli_connect doesn't target the table and mysqli_query doesn't output anything.


1 Answers

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.

like image 61
awgy Avatar answered Sep 28 '22 10:09

awgy