Page 1 of 1
mysql prepare
Posted: Wed Apr 09, 2008 6:51 am
by gunmark
hi all
am new to php .. am running the following code to connect my DB..
$conn = new mysqli('localhost', 'phpuser', 'phpuser', 'phpdb');
$stmt = $conn->prepare($loginSql);
$stmt->bind_param("s", $username);
$stmt->execute();
but am getting Fatal error: Call to a member function bind_param() on a non-object in error.. cud any1 help me out of dis
Re: mysql prepare
Posted: Wed Apr 09, 2008 7:07 am
by EverLearning
Whats the value of $loginSql? Is it even defined?
Re: mysql prepare
Posted: Wed Apr 09, 2008 7:10 am
by gunmark
no.. no.. it has
var $loginSql = "select * from login where username=?";
Re: mysql prepare
Posted: Wed Apr 09, 2008 8:06 am
by EverLearning
var $loginSql = "select * from login where username=?";
Why is there a
var before
$loginSql? Is this a class property? If so, you access it with
$this->loginSql(if you're inside the class), not just
$loginSql. That would explain the error you've been getting.
Post a more complete code example.
Re: mysql prepare
Posted: Wed Apr 09, 2008 8:22 am
by gunmark
here is my code
$loginSql = "select userId from user where username=?";
$conn = new mysqli('localhost', 'phpuser', 'phpuser', 'phpdb');
$stmt = $conn->prepare($loginSql);
$stmt->bind_param("s", $username);
$stmt->execute();
when i tried to run this code am getting
Fatal error: Call to a member function bind_param() on a non-object in D:\Web\WebServer\Apache2\htdocs\DbConn\test.php on line 10
Re: mysql prepare
Posted: Wed Apr 09, 2008 8:23 am
by EverLearning
Also turn on error reporting to full
Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);