eburroughs Posted August 6, 2009 Share Posted August 6, 2009 I'm using prepared mysqli_stmt variables in an object-oriented fashion to communicate with my MySQL server. Something's not quite right with the SQL statement I prepared, and I want to print out the query to see what's wrong with it, but I can't find a way to print out the query held within a mysqli_stmt object. I'm used to doing things the old fashioned way where you just define a query in a (easily printable) string and pass that to mysql_query(). How do I print the query held inside a mysqli_stmt? Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/ Share on other sites More sharing options...
MatthewJ Posted August 6, 2009 Share Posted August 6, 2009 You should post the code, it might help get an answer. Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-892292 Share on other sites More sharing options...
eburroughs Posted August 6, 2009 Author Share Posted August 6, 2009 Sure: $conn = new mysqli("********","****","*****","*****"); .... $statement = $conn->prepare("INSERT INTO foo VALUES(?,?,INET_ATON(?),NOW())"); $statement->bind_param('sss', $string1, $string2, $_SERVER['REMOTE_ADDR']); $statement->execute(); $statement->close(); My query is executing, but not doing exactly what I want. I would like to see the raw text of the SQL query. I've tried print_r($statement) and var_dump($statement), but they don't give me the info I need. Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-892313 Share on other sites More sharing options...
eburroughs Posted August 21, 2009 Author Share Posted August 21, 2009 bump Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-903067 Share on other sites More sharing options...
play_ Posted August 21, 2009 Share Posted August 21, 2009 You can't. best thing to do is put it in a string (ie. $query = "INSERT INTO foo VALUES('$whatever', '$something'.....) and echo $query. Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-903072 Share on other sites More sharing options...
eburroughs Posted August 21, 2009 Author Share Posted August 21, 2009 I find that very surprising. Oh well, thanks play_ for the response. Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-903441 Share on other sites More sharing options...
play_ Posted August 21, 2009 Share Posted August 21, 2009 No prob. If the query throws an error, you can see it by $sql->errorInfo() http://php.mirror.facebook.net/manual/en/pdostatement.errorinfo.php Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-903579 Share on other sites More sharing options...
play_ Posted August 21, 2009 Share Posted August 21, 2009 No prob. If the query throws an error, you can see it by $sql->errorInfo() http://php.mirror.facebook.net/manual/en/pdostatement.errorinfo.php Here's some more useful info http://stackoverflow.com/questions/210564/pdo-prepared-statements Link to comment https://forums.phpfreaks.com/topic/169115-solved-printing-the-query-within-a-mysqli_stmt/#findComment-903581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.