开发者

PHP MySQL Query Printing

Is there anyway I can see a query once it has been run and all variables have been instantiated?

e.g. I want to see the end result (String) of

$query = $this->db->query("SELECT email, password FROM users
    WHE开发者_C百科RE email = '$email' AND password = 'PASSWORD($password)'");

I would like to see the query string after PASSWORD($password) has been done.


The query string doesn't change inside MySql, but you can do something like this to see what the password will look like:

$query = $this->db->query("SELECT PASSWORD('".mysql_real_escape_string($password)."')");


You can store the string as a variable before hand.

eg)

$query = "SELECT email, password FROM users
    WHERE email = '$email' AND password = 'PASSWORD($password)'";

and then output the query with var_dump($query).

$this->db->query($query);

It is better practice though to use prepared statements and feed in escaped variables.


I needed to change 'PASSWORD($password)'

to:

PASSWORD('$password')

This fixed my issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜