Reputation: 893
I have a SQL statement that doesnt seem to be working, I've spent over an hour asking how to show what the statement looks like example:
$result = mysql_query("SELECT * FROM myTable WHERE id=$my_id AND status=$active");
Now all I need to do is view what the actual SQL is passed so I imagine it looks like this:
SELECT * FROM myTable WHERE id=2 AND status=4
I know this is probably super simple but the keywords im searching is not bringing back the answers, I've tried print_r
, echo $result
, mysql_fetch_array
, etc. and it's not really getting what I need, can someone put me out of misery and tell me how I can get back the hour of my life i just wasted?
Upvotes: 0
Views: 138
Reputation: 6802
$sql = 'SELECT * FROM myTable WHERE id='.mysqli_escape_string($my_id).' AND status='.mysqli_escape_string($active); $result = mysqli_query($sql) or die mysqli_error()." Query:".$sql;
Use mysqli
instead of mysql
because mysql
is deprecated Link.
Upvotes: 0
Reputation: 128
$sql = 'SELECT * FROM myTable WHERE id='.is_int($my_id).' AND status='.is_int($active);
$result = mysql_query($sql);
echo $sql;
Upvotes: 2
Reputation: 1169
Just echo it.
echo "SELECT * FROM myTable WHERE id=$my_id AND status=$active";
Upvotes: 1