Jump to content

Recommended Posts

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());

Link to comment
https://forums.phpfreaks.com/topic/119107-member-function-execute-on-a-non-object/
Share on other sites

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 :)

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 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.

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!

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!

 

  • 10 months later...

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!!!

 

  • 2 weeks later...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.