roger
roger

Reputation: 33

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
    WHERE email = '$email' AND password = 'PASSWORD($password)'");

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

Upvotes: 0

Views: 139

Answers (3)

cambraca
cambraca

Reputation: 27835

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)."')");

Upvotes: 3

roger
roger

Reputation: 33

I needed to change 'PASSWORD($password)'

to:

PASSWORD('$password')

This fixed my issue.

Upvotes: 0

brian_d
brian_d

Reputation: 11385

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.

Upvotes: 0

Related Questions