469,352 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

PDOStatement error : Call to a member function execute() on a non-object

Hello,

I'm encountering a strange error with PDO. The server is FreeBSD 4.4,
PHP 5.1.2, mySQL 4.0.20 with 4.1.18 client libs.

I have the following code (usernames and passwords changed to protected
the innocent ^_^)

<?
$db_dsn = "mysql:host=dbHost;dbname=dbName";
$db_username = "username";
$db_password = "password";
$db = new PDO($db_dsn, $db_username, $db_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("SELECT * FROM myTable");
$statement->execute();
?>

I get an error on the last line "Fatal error: Call to a member function
execute() on a non-object"

What's strange is this code works fine on my development servers, and
used to work fine on this server up until a few days ago. I've
restarted the server several times, recompiled php with the following
configure script

../configure --with-pdo-mysql=/usr/local/mysql --with-curl=/usr/local
--enable-versioning --enable-memory-limit --with-layout=GNU
--enable-ctype --enable-overload --enable-posix --enable-session
--enable-tokenizer --with-expat-dir=/usr/local --with-imap=/usr/local
--with-jpeg-dir=/usr/local --with-mysql=/usr/local/mysql
--with-pcre-regex=yes --with-png-dir=/usr/local --with-zlib-dir=/usr
--with-zlib=yes --with-regex=php --enable-cli
--with-apxs2=/usr/local/www/bin/apxs --prefix=/usr/local
i386--freebsd4.4 --enable-spl --with-pdo --enable-pdo
--with-gd=/usr/local --disable-all

This is the only script that gets run so there's definitely no problems
with open cursors (I've read the posts about
PDOStatement::closeCursor()).

The only thing I can think of is that the 4.1.18 mySQL client libs wont
work with PDO and mySQL 4.0.20. I've tested with old-school mysql
functions (mysql_connect) and it works fine, its only PDO that breaks.

Does anyone have any idea? Thanks so much for any help.

~Kevin

Nov 15 '06 #1
5 16171
..oO(lo*********@gmail.com)
><?
$db_dsn = "mysql:host=dbHost;dbname=dbName";
$db_username = "username";
$db_password = "password";
$db = new PDO($db_dsn, $db_username, $db_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("SELECT * FROM myTable");
$statement->execute();
?>

I get an error on the last line "Fatal error: Call to a member function
execute() on a non-object"
There's no error handling.

PDO::prepare() returns FALSE if something goes wrong.
Then check PDO::errorInfo() to get more informations.

Micha
Nov 15 '06 #2
I added a print_r of $db->errorInfo() before the execute statement and
get the following

Array
(
[0] =00000
[1] =1047
[2] =Unknown command
)

On Nov 15, 2:38 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(loudwins...@gmail.com)
<?
$db_dsn = "mysql:host=dbHost;dbname=dbName";
$db_username = "username";
$db_password = "password";
$db = new PDO($db_dsn, $db_username, $db_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("SELECT * FROM myTable");
$statement->execute();
?>
I get an error on the last line "Fatal error: Call to a member function
execute() on a non-object"There's no error handling.

PDO::prepare() returns FALSE if something goes wrong.
Then check PDO::errorInfo() to get more informations.

Micha
Nov 15 '06 #3
..oO(lo*********@gmail.com)
>I added a print_r of $db->errorInfo() before the execute statement and
get the following

Array
(
[0] =00000
[1] =1047
[2] =Unknown command
)
I should have had a look on your MySQL version before - prepared
statements require MySQL 4.1 or higher.

Your client lib supports them, but not the server itself.

Micha
Nov 15 '06 #4
Okay figured it out. Somehow the server has two version of mySQL
(4.1.18 and 4.0.20) and the 4.0 version was running. Once I got the
4.1 install up and running everything worked fine.

Thanks for your help!

~Kevin

On Nov 15, 3:19 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(loudwins...@gmail.com)
I added a print_r of $db->errorInfo() before the execute statement and
get the following
Array
(
[0] =00000
[1] =1047
[2] =Unknown command
)I should have had a look on your MySQL version before - prepared
statements require MySQL 4.1 or higher.

Your client lib supports them, but not the server itself.

Micha
Nov 15 '06 #5
lo*********@gmail.com wrote:
Hello,

I'm encountering a strange error with PDO. The server is FreeBSD 4.4,
PHP 5.1.2, mySQL 4.0.20 with 4.1.18 client libs.

I have the following code (usernames and passwords changed to protected
the innocent ^_^)

<?
$db_dsn = "mysql:host=dbHost;dbname=dbName";
$db_username = "username";
$db_password = "password";
$db = new PDO($db_dsn, $db_username, $db_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $db->prepare("SELECT * FROM myTable");
$statement->execute();
?>

I get an error on the last line "Fatal error: Call to a member function
execute() on a non-object"

What's strange is this code works fine on my development servers, and
used to work fine on this server up until a few days ago. I've
restarted the server several times, recompiled php with the following
configure script

./configure --with-pdo-mysql=/usr/local/mysql --with-curl=/usr/local
--enable-versioning --enable-memory-limit --with-layout=GNU
--enable-ctype --enable-overload --enable-posix --enable-session
--enable-tokenizer --with-expat-dir=/usr/local --with-imap=/usr/local
--with-jpeg-dir=/usr/local --with-mysql=/usr/local/mysql
--with-pcre-regex=yes --with-png-dir=/usr/local --with-zlib-dir=/usr
--with-zlib=yes --with-regex=php --enable-cli
--with-apxs2=/usr/local/www/bin/apxs --prefix=/usr/local
i386--freebsd4.4 --enable-spl --with-pdo --enable-pdo
--with-gd=/usr/local --disable-all

This is the only script that gets run so there's definitely no problems
with open cursors (I've read the posts about
PDOStatement::closeCursor()).

The only thing I can think of is that the 4.1.18 mySQL client libs wont
work with PDO and mySQL 4.0.20. I've tested with old-school mysql
functions (mysql_connect) and it works fine, its only PDO that breaks.

Does anyone have any idea? Thanks so much for any help.

~Kevin
Kevin,

It looks like your prepare call has a problem.

You should always check the return value. If falls, call
db->errorInfo() and display your error message. It should help you find
your problem.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

37 posts views Thread by Ben | last post: by
2 posts views Thread by dmitry.freitor | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.