Jump to content

function that calls a "class function" outsid itself


gladideg

Recommended Posts

I'm using this MySQL wrapper for communicating with my database: www.ricocheting.com/scripts/php_mysql_wrapper.php

 


$configoptions = ip,username,password,table.....
$db = new Database($configoptions);
$db->connect();
$row = $db->query_first("select * from whatever");
echo $row[column1];

 

... This works just fine, and the wrapper is pretty satisfying.

 

Now my problem is when I try to call the $db->  object from within a function, outside the Database class.

 

 

function checkSomething($uuid){

     $row = $db->query("select UUID from someTable WHERE UUID = $uuid");

     if($db->affected_rows > 0){
          return true;
     }
     else {
          return false;
     }

}

 

Call to a member function query() on a non-object in

 

I'm not into OOP, but I'm trying to learn it step by step. Right now I only need to communicate with this Database object. Not fully understand it.

 

Hope someone can help me out ;)

 

Best regards

function checkSomething($uuid){
GLOBAL $db; // This addition should do it
     $row = $db->query("select UUID from someTable WHERE UUID = $uuid");

     if($db->affected_rows > 0){
          return true;
     }
     else {
          return false;
     }

}

 

function checkSomething($uuid){
GLOBAL $db; // This addition should do it
     $row = $db->query("select UUID from someTable WHERE UUID = $uuid");

     if($db->affected_rows > 0){
          return true;
     }
     else {
          return false;
     }

}

 

 

Ugh.  Don't use global.  Argument lists exist for a reason.  Instead, use:

 

function check($dbc, $uuid)
{
   $row = $dbc->query("SELECT UUID FROM someTable WHERE UUID = $uuid");

   if ($dbc->affected_rows > 0) { return true; }
   else { return false; }
}

Ugh.  Don't use global.  Argument lists exist for a reason.  Instead, use:

 

Fair call, I did after all come here an hour or so ago to get help myself.... now 8am, no sleep.. will leave even the easy problems to you xperts  :-[

Archived

This topic is now archived and is closed to further replies.

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