Jump to content

function that calls a "class function" outsid itself


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

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.