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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
eburroughs Posted August 21, 2009 Author Share Posted August 21, 2009 bump Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.