Afficher un message
Vieux 17/02/2008, 15h27   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error using prepared statements in PHP

kodaliece@gmail.com wrote:
> Hi,
>
> I am using prepared statements and executing the below small script.
>
> <?php
> $username="root";
> $password="admin";
> $database="test";
>
> // 'Connect to database'
> $con = mysql_connect('localhost', $username, $password, $database) or
> die(mysql_error());
>
> if (!($con))
> {
> echo "<BR>Cannot connect to datbase. Please try again Later...";
> }
> else
> {
> $user_query = "SELECT first_name, UserImage FROM userdata WHERE
> loginid = ? AND password = ?";
>
> $statement = $con->prepare($user_query); // This line is ging the
> error
> $statement->bind_param("ss", $_POST['login_id'], $_POST['password']);
>
> $result = $statement->execute();
>
>
> // 'Close database connection'
>
> if (mysql_close($con))
> echo "<BR>Database connection closed";
> else
> echo "<BR>Failed to close database connection";
>
> }
> ?>
>
> But I get the error:
> Fatal error: Call to a member function prepare() on a non-object in C:
> \Program Files\apache-tomcat-5.5.26\webapps\LoginValidate.php on line
> 17.
>
> Can any please me on this.
>
> Thanks
> Mohan
>


mysql_connect() is a functional interface to MySQL, not an OO one. It
returns a connection resource, not an object. Also, the mysql_
interface doesn't support prepared statements.

I suspect you want the mysql improved extension. It is an OO interface
which supports prepared statements (and, BTW, is more efficient than PDO).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
 
Page generated in 0,45462 seconds with 9 queries