mysql prepare

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gunmark
Forum Newbie
Posts: 4
Joined: Wed Apr 09, 2008 6:48 am

mysql prepare

Post 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
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: mysql prepare

Post by EverLearning »

Whats the value of $loginSql? Is it even defined?
gunmark
Forum Newbie
Posts: 4
Joined: Wed Apr 09, 2008 6:48 am

Re: mysql prepare

Post by gunmark »

no.. no.. it has

var $loginSql = "select * from login where username=?";
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: mysql prepare

Post 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.
gunmark
Forum Newbie
Posts: 4
Joined: Wed Apr 09, 2008 6:48 am

Re: mysql prepare

Post 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
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: mysql prepare

Post by EverLearning »

Also turn on error reporting to full

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);
Post Reply