So I have my query in which I am trying to get the "password" field to return because I am having issues with my login:
$res = $db->query("SELECT `password` FROM users WHERE username = 'joeybab3'");
and I get the error :
"object of class mysql_result cannot be converted to a string"
So some googling got me this:
list($res) = $res->fetch_row;
but that just returns blank when I use echo.
mysqli::query
method returns a mysqli_result
object. It is an object, that's why you cannot use echo to print it out.
You need to use fetch_array/fetch_assoc/fetch_row methods to really get the data out of it.
In this case, you could use:
$row = $res->fetch_assoc();
$password = $row['password'];
echo $password;
fetch_row is a function, calling it like this should work.
list($res) = $res->fetch_row();
Edit:
Looks like you're using the MySQL library which has been deprecated. You should choose a different api if possible.
Then use this code:
$sql = "SELECT 'password' FROM users WHERE username = 'joeybab3'";
and echo $sql
.
This is how I would do it.