Page 1 of 1
How do I check what a query is doing?
Posted: Wed Mar 06, 2013 4:06 am
by simonmlewis
Code: Select all
include "dbconn.php";
$result = mysql_query ("SELECT id, romancode, players FROM events WHERE romancode = '$itemcode'") or die(mysql_error());
This is producing nothing, yet it should be a very basic query. I've tested and $itemcode has something in it.
So how do I 'print' what $result is producing - I've totally forgotten.
Re: How do I check what a query is doing?
Posted: Wed Mar 06, 2013 6:42 am
by Celauran
You mean var_dump? I'd also move the query itself into a variable and echo that.
Re: How do I check what a query is doing?
Posted: Wed Mar 06, 2013 6:45 am
by simonmlewis
Hi. I need some form of example please.
However, the root issue here has been resolved. It seems that there was hidden code in the variable, which I discovered and have since stripped out.
Re: How do I check what a query is doing?
Posted: Wed Mar 06, 2013 10:16 am
by social_experiment
Code: Select all
<?php
$result = mysql_query ("SELECT id, romancode, players FROM events WHERE romancode = '$itemcode'");
var_dump($result);
?>
Depending on what the return result is you can figure out whether the query failed or not (in case of a SELECT statement, mysql_query() will return a resource on success and false on failure.
Re: How do I check what a query is doing?
Posted: Mon Mar 11, 2013 2:45 am
by Jessica159
Dear, visit this page
http://stackoverflow.com/questions/1532 ... ted-in-pdo... hopefully it will be useful for you.
Re: How do I check what a query is doing?
Posted: Mon Mar 11, 2013 3:36 am
by requinix
Since OP isn't using PDO (though it's a good idea to
switch to it) I wouldn't hold my breath.
Re: How do I check what a query is doing?
Posted: Mon Mar 11, 2013 10:29 am
by simonmlewis
I get this:
bool(true)
I'm doing an INSERT query now. But the data isn't going in.
Re: How do I check what a query is doing?
Posted: Tue Mar 12, 2013 12:20 am
by social_experiment
Celauran wrote:move the query itself into a variable and echo that.
what output do you receive when you echo the query?
Re: How do I check what a query is doing?
Posted: Tue Mar 12, 2013 4:17 pm
by Christopher
Do you mean how do you return the result set?
Code: Select all
include "dbconn.php";
$error = '';
$rows = array();
$result = mysql_query ("SELECT id, romancode, players FROM events WHERE romancode = '$itemcode'");
if (!mysql_errno($result)) {
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
} else {
$error = mysql_error($result);
}
echo "error=$error<br/>";
echo 'rows=<pre>' . print_r($rows, 1) . '</pre>';