I'm trying to build a website using object-oriented functionality, and running into some issues. The one that is currently vexing me is an error message that I can't solve:
Fatal error: Call to a member function real_escape_string() on a non-object in /home/rilbur5/public_html/tutor/login.php on line 41
function get_user_MYSQL(){
return new mysqli($GLOBALS['db_host'],$GLOBALS['user_login'],$GLOBALS['user_password'],$GLOBALS['db_name']);
}//will turn this into a singleton object later
class User_Login{
private $db_link;
public function __construct()
{
$db_link=get_user_MYSQL();
}
public function bar($foo)
{
$foo=$db_link->real_escape_string($foo);
}
}
I've inserted an echo statement into the constructor, and it IS being called. I've tested the get_user function, and it works elsewhere -- in fact, I used an echo statement that showed that the data was, in fact, being properly escaped when I used real_escape_string on an object produced by the get_user functions. So why is the combination not producing a mySQLi function that will do the necessary work?