473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 16478
..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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
2
by: dmitry.freitor | last post by:
Why would someone call a non-static provate member function from another non-static member function of the same class via the this pointer? Thanks. DF
6
by: bluekite2000 | last post by:
I have Vector<complex<float> > V(5); V.rand(); Vector<float> V1(V); //specialized function here to return norm(V). This works fine Vector<double> V2(5); V2.rand(); Vector<float>...
1
by: bluekite2000 | last post by:
Here is the compilable code, along w/ the error #include<iostream> #include<complex> typedef std::complex<float> ComplexSingle; using namespace std; template<typename T> class X { private:...
8
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
9
by: java | last post by:
Hey there, I just removed an elderly PHP4-Installation from my Windows-Box and installed PHP 5.2.1. I used the PHP4-Module as local batchfile- interpreter by E:\ersDHCP>php ./extractLog.php ...
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
2
by: Elliott | last post by:
Hello Everyone, I have a function in a header (KeyDialog.h) as such: void setKey(Key&); The function implementation is as such (KeyDialog.cpp): void KeyDialog::setKey(Key& k1) {
10
by: randysimes | last post by:
I am trying to pass uid and pwd to the function CheckPW of the class PWServer. I receive the error pwclient.cpp:41: error: cannot call member function âint PWServer::CheckPW(const char*, char*)â...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.