I have a question for you guys. I am trying to make MySQL run as securely as possible. Currently, I am wondering if it is possible to get an object with MySQLi after I prepared the statement, bound the parameters and executed the statement.
Example:
$sql = $mysqli->prepare('SELECT * FROM users WHERE username = ?;'); $sql->bind_param('s', $username); $username = 'RastaLulz'; $sql->execute(); $object = $sql->fetch_object(); echo $object->mail;
I get the following error:
Fatal error: Call to a member function fetch_object() on a non-object in C:\xampp\htdocs\ProCMS\DevBestCMS\inc\global\class.mysql.php on line 23
However, when I add "$ sql-> result_metadata ();" I am not getting an error, but it does not return a result (this is just NULL).
$sql = $mysqli->prepare('SELECT * FROM users WHERE username = ?;'); $sql->bind_param('s', $username); $username = 'RastaLulz'; $sql->execute(); $result = $sql->result_metadata(); $object = $result->fetch_object(); echo $object->mail;
So you can do this without binding parameters:
$sql = $mysqli->query("SELECT * FROM users WHERE username = 'RastaLulz';"); $object = $sql->fetch_object(); echo $object->mail;
Here is my current MySQL class - you just need to make the execute function work. http://uploadir.com/u/lp74z4
Any help would be appreciated!
php mysqli
Josh foskett
source share