|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
*** kodaliece@gmail.com escribió/wrote (Sun, 17 Feb 2008 03:19:06 -0800 (PST)):
> $con = mysql_connect('localhost', $username, $password, $database) or > die(mysql_error()); [...] > $statement = $con->prepare($user_query); > 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. If $con is the return value of mysql_connection(), then it can't have a method called prepare(), mainly because it's not even an object: usage: resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] ) Return Values Returns a MySQL link identifier on success, or FALSE on failure. My best guess is that you want to use PDO. Then you need to create an instance of a PDO object (adapt the example to your code): $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)"); More info: http://www.php.net/pdo -- -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain ++ Mi sitio sobre programación web: http://bits.demogracia.com +- Mi web de humor austrohúngaro: http://www.demogracia.com -- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 ================== |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Hi,
By Searching on internet for some time I came to know that, as you said, I have to use PDO. So I tried to use it. But I get the error: Fatal error: Class 'PDO' not found. So, I did the following steps which I get from some website: I changed the file "php.ini", by removing the comments at the following lines: extension=php_pdo.dll extension=php_pdo_sqlite.dll extension=php_sqlite.dll Then I copied these files to the system32 folder. Still I got the same error. Can you please tell me how to resolve this Thanks Mohan On 17 Feb, 19:27, Jerry Stuckle <jstuck...@attglobal.net> wrote: > kodali...@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. > jstuck...@attglobal.net > ==================- Hide quoted text - > > - Show quoted text - |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
kodaliece@gmail.com wrote:
> Hi, > > By Searching on internet for some time I came to know that, as you > said, I have to use PDO. So I tried to use it. But I get the error: > Fatal error: Class 'PDO' not found. > > So, I did the following steps which I get from some website: > > I changed the file "php.ini", by removing the comments at the > following lines: > extension=php_pdo.dll > extension=php_pdo_sqlite.dll > extension=php_sqlite.dll > > Then I copied these files to the system32 folder. Still I got the same > error. Can you please tell me how to resolve this > > Thanks > Mohan > > > > On 17 Feb, 19:27, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> kodali...@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. >> jstuck...@attglobal.net >> ==================- Hide quoted text - >> >> - Show quoted text - > > They don't go in the systems folder - you need to set the extension directory in your php.ini file, then ensure those files are in the extension directory. See the comments in the php.ini file for more information. And ensure you're changing the correct php.ini file. See what phpinfo() says about it. And BTW - PDO doesn't really "support" prepared statements. Rather, it emulates them. The only MySQL code in PHP which currently supports true prepared statements is the MySQL Improved Interface, mysqli. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Feb 18, 8:53am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> kodali...@gmail.com wrote: > > Hi, > > > By Searching on internet for some time I came to know that, as you > > said, I have to use PDO. So I tried to use it. But I get the error: > > Fatal error: Class 'PDO' not found. > > > So, I did the following steps which I get from some website: > > > I changed the file "php.ini", by removing the comments at the > > following lines: > > extension=php_pdo.dll > > extension=php_pdo_sqlite.dll > > extension=php_sqlite.dll > > > Then I copied these files to the system32 folder. Still I got the same > > error. Can you please tell me how to resolve this > > > Thanks > > Mohan > > > On 17 Feb, 19:27, Jerry Stuckle <jstuck...@attglobal.net> wrote: > >> kodali...@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. > >> jstuck...@attglobal.net > >> ==================- Hide quoted text - > > >> - Show quoted text - > > They don't go in the systems folder - you need to set the extension > directory in your php.ini file, then ensure those files are in the > extension directory. See the comments in the php.ini file for more > information. > > And ensure you're changing the correct php.ini file. See what phpinfo() > says about it. > > And BTW - PDO doesn't really "support" prepared statements. Rather, it > emulates them. The only MySQL code in PHP which currently supports true > prepared statements is the MySQL Improved Interface, mysqli. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ==================- Hide quoted text - > > - Show quoted text - Hi, Can you please tell me how to use mysqli. Here are some details about my php.ini file: phpinfo() is using the php.ini located at C:\WINDOWS\php.ini In PHP file, I am using, extension_dir = "C:/Program Files/PHP" and uncommented the following lines: ;extension=php_pdo.dll ;extension=php_pdo_sqlite.dll ;extension=php_sqlite.dll These three files are available in C:/Program Files/PHP/ext Thanks Mohan |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
kodaliece@gmail.com wrote:
> Can you please tell me how to use mysqli. Uncomment extension=php_mysqli.dll. > In PHP file, I am using, extension_dir = "C:/Program Files/PHP" > These three files are available in C:/Program Files/PHP/ext Isn't the problem obvious? Bye! |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Feb 18, 11:24am, Anonymous <anonym...@nowhere.invalid> wrote:
> kodali...@gmail.com wrote: > > Can you please tell me how to use mysqli. > > Uncomment extension=php_mysqli.dll. > > > In PHP file, I am using, extension_dir = "C:/Program Files/PHP" > > These three files are available in C:/Program Files/PHP/ext > > Isn't the problem obvious? > > Bye! Hi, I Uncommented extension=php_mysqli.dll and able to connect to database. But now I am facing another problem. Below are the few lines from my code: $statement = $db_connection->prepare($user_query); $statement->bind_param("ss", $_POST['login_id'], $_POST['password']); $result = $statement->execute(); $num=mysqli_num_rows($result); // This line is giving error In this code I am trying to count the number of rows returned by the query. But, I get the error, "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" at the line I marked in the code. Can anyone please suggest me how to get the resultset. Thanks Mohan |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Hi All,
I am able to resolve this. Thanks for your , Mohan |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
kodaliece@gmail.com wrote:
> I Uncommented extension=php_mysqli.dll and able to connect to > database. But now I am facing another problem. > Below are the few lines from my code: > $statement = $db_connection->prepare($user_query); > $statement->bind_param("ss", $_POST['login_id'], $_POST['password']); > $result = $statement->execute(); > $num=mysqli_num_rows($result); // This line is giving error > In this code I am trying to count the number of rows returned by the > query. But, I get the error, "Warning: mysqli_num_rows() expects > parameter 1 to be mysqli_result, boolean given" at the line I marked > in the code. Well, the error message is very clear. mysqli_stmt_execute returns a boolean, 0 on failure and 1 on success and not a result set. mysqli_num_rows can only be executed after a normal query, what you need is mysqli_stmt_num_rows. Try this: $statement = $db_connection->prepare($user_query); $statement->bind_param("ss", $_POST['login_id'], $_POST['password']); $statement->execute(); $statement->store_result(); $num = $statement->num_rows; P.S.: Stick to one style, procedural or object oriented. Don't mix them. Bye! |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
..oO(Jerry Stuckle)
>And BTW - PDO doesn't really "support" prepared statements. Rather, it >emulates them. The only MySQL code in PHP which currently supports true >prepared statements is the MySQL Improved Interface, mysqli. It depends on the driver. The PDO_MYSQL driver uses native prepared statements if available. For older versions of MySQL they will be emulated. Micha |
|
![]() |
| Outils de la discussion | |
|
|