Sven70 Posted August 11, 2008 Share Posted August 11, 2008 Hi, I am new with MySQL! I have created now a small PHP class to create two tables in my database, but when I run it, I got following error message: Call to a member function Execute() on a non-object Can somebody have a look and explain what I missed or made wrong! Here come my class: <?php error_reporting(E_ALL); include('adodb5/adodb.inc.php'); include('adodb5/adodb-active-record.inc.php'); try { $db = NewADOConnection("mysql://$user:$pwd@$server/$db?persist"); $db->Execute("CREATE TABLE 't_vehicle' ( 'id' int(20) NOT NULL auto_increment, 'manufacturer' varchar(50) unsigned NOT NULL auto_increment, 'model' varchar(50) NOT NULL default '', 'color' varchar(50) NOT NULL default '', 'price' varchar(50) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM; "); $db->Execute("CREATE TABLE 't_vehicleoptions' ( 'id' int(20) NOT NULL auto_increment, 'model' varchar(50) NOT NULL default '', 'airbags' int(1) default NULL,, 'aircondition' varchar(3) NOT NULL default 'NO', 'radio' varchar(50) NOT NULL default '', 'snowtyre' varchar(50) NOT NULL default '', PRIMARY KEY ('id') ) ENGINE=MyISAM; "); } catch (exception $e) { var_dump($e); adodb_backtrace($e->gettrace()); Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/ Share on other sites More sharing options...
Johntron Posted August 12, 2008 Share Posted August 12, 2008 It looks like the following line isn't working as expected: $db = NewADOConnection("mysql://$user:$pwd@$server/$db?persist"); $db is probably false after that point, because the NewADOConnection() is obviously not returning an object. Be sure to add some exception handling there Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614131 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 I think you want: $db = new ADOConnection("mysql://$user:$pwd@$server/$db?persist"); Notice how new is its own keyword. Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614145 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 I think you want: $db = new ADOConnection("mysql://$user:$pwd@$server/$db?persist"); Notice how new is its own keyword. Oddly enough, ADODB uses the function NewADOConnection() to create the db instance, instead of creating the object in the traditional way.. though I can see how it would be deceptive (it's weird). To the op: Try using the alternative syntax, you might have better luck... <?php $db = NewADOConnection('mysql'); $db->PConnect($server, $user, $pwd, $db); // Or Connect() if you don't want a persistent connection ?> Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614158 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 I think you want: $db = new ADOConnection("mysql://$user:$pwd@$server/$db?persist"); Notice how new is its own keyword. Oddly enough, ADODB uses the function NewADOConnection() to create the db instance, instead of creating the object in the traditional way.. though I can see how it would be deceptive (it's weird). To the op: Try using the alternative syntax, you might have better luck... <?php $db = NewADOConnection('mysql'); $db->PConnect($server, $user, $pwd, $db); // Or Connect() if you don't want a persistent connection ?> I figured as much after I posted because I realized it didn't throw back an Undefined Function error. That is weird though. D: Stupid ADODB and their non-conformist methods. Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614166 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 Hah, it confused me at first too, I've never used adodb. I had to google it to find out more Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614171 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Hah, it confused me at first too, I've never used adodb. I had to google it to find out more Yeah, I've never used it either. >_< Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614172 Share on other sites More sharing options...
Sven70 Posted August 12, 2008 Author Share Posted August 12, 2008 Dear All, Thanks for your help! I tried now serveral things, but all are not running. include('../library/adodb5/adodb.inc.php'); include('../library/adodb5/adodb-active-record.inc.php'); try { $db = NewADOConnection("mysql"); $db->Connect(localhost, Sven, Sventest, $db); // $db = NewADOConnection("mysql://Sven:Sventest@localhost/ibdata1?persist"); // $db = NewADOConnection("mysql://$user:$pwd@$server/$db?persist"); ADOdb_Active_Record::SetDatabaseAdapter($db); $db->Execute("CREATE TABLE 't_vehicle' ( ... Fatal error: Call to undefined function mysql_connect() in C:\server\library\adodb5\drivers\adodb-mysql.inc.php on line 63 Any ideas? Why is the adodb function mysql_connect() undefined? When PConnect function, comes same error message for mysql_Pconnect()! Is something missing in my installation? I have installed: * PHP version 5.2.6 * MYSQL Server version 5.0.67-community-nt Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614295 Share on other sites More sharing options...
genericnumber1 Posted August 12, 2008 Share Posted August 12, 2008 Call to undefined function mysql_connect() help: http://www.phpfreaks.com/forums/index.php/topic,95378.0.html And yes, that's what's causing the non-object error you mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614301 Share on other sites More sharing options...
Sven70 Posted August 12, 2008 Author Share Posted August 12, 2008 Thanks a lot. This is also solved now for me the error message. But I get now a error message for the Execute() function: Fatal error: Call to a member function Execute() on a non-object As I am new with MySQL, do you also know, what must I change here? Or is also something missing? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-614353 Share on other sites More sharing options...
RockRunner Posted July 9, 2009 Share Posted July 9, 2009 Hey guys, I am also receiving this same message: "Fatal error: Call to a member function Execute() on a non-object" Here is the code where the error is: function Subscriber_Type($dbh) { global $site; $stack = array(); $query = "SELECT Description FROM SubscriberTypes"; $res = $dbh->Execute($query); if(!$res) { echo "'$query': "; $dbh->ErrorMsg(); } while (!$res->EOF) { $stack[] = $res->fields['Description']; $res->MoveNext(); } //print $dbh; echo "<pre>"; print_r($stack); echo "</pre>"; // actual display $site->display("main.tpl"); } Any Ideas? Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-872181 Share on other sites More sharing options...
genericnumber1 Posted July 9, 2009 Share Posted July 9, 2009 You'll have to show us the code where you call the Subscriber_Type function. Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-872327 Share on other sites More sharing options...
RockRunner Posted July 21, 2009 Share Posted July 21, 2009 I ended up just trashing that file and starting over.. but thanks any way!!!! (the new version of the file works) Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-879700 Share on other sites More sharing options...
Maq Posted July 21, 2009 Share Posted July 21, 2009 I ended up just trashing that file and starting over.. but thanks any way!!!! (the new version of the file works) For future reference it's probably better if you start your own thread and post a link to this one stating it's a similar problem. Your original post resurrected a thread from nearly a year ago. Glad you got everything working though. Quote Link to comment https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/#findComment-879720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.