I'm new to the mysqli prepared statements, and I'm a bit concerned that what I'm sending to the database is not exactly what is being executed. How can I get the code from MySQL that is to be or was executed, with the parameters in place? Used to be I would just set $query = "select stuff from my tables" and right before I ran the query I would just echo "The query is $query" and I'd know exactly what was going on.
Thanks in advance for your help.
How do I get a prepared query as it will execute?
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How do I get a prepared query as it will execute?
So far as I know, you can't. Just trust that it escapes and quotes your values.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: How do I get a prepared query as it will execute?
There has to be a way to get the query as submitted to the database with the parameters populated. There just has to be.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How do I get a prepared query as it will execute?
Good luck. I Thought so too, but doing a var_dump($stmt) yields nothing resembling the query:psyclo wrote:There has to be a way to get the query as submitted to the database with the parameters populated. There just has to be.
Code: Select all
$id = 1;
$stmt = $mysqli->prepare("SELECT* FROM something WHERE id = ?")) {
$stmt->bind_param("i", $id);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- Pyrite
- Forum Regular
- Posts: 769
- Joined: Tue Sep 23, 2003 11:07 pm
- Location: The Republic of Texas
- Contact:
Re: How do I get a prepared query as it will execute?
Try using the General Query Log feature in MySQL.
http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Also, many PHP frameworks log this as well, with certain debug levels turned on (e.g. CakePHP with Debug Level 2).
http://dev.mysql.com/doc/refman/5.1/en/query-log.html
Also, many PHP frameworks log this as well, with certain debug levels turned on (e.g. CakePHP with Debug Level 2).