gladideg Posted September 17, 2009 Share Posted September 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/174639-function-that-calls-a-class-function-outsid-itself/ Share on other sites More sharing options...
ozestretch Posted September 17, 2009 Share Posted September 17, 2009 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/174639-function-that-calls-a-class-function-outsid-itself/#findComment-920382 Share on other sites More sharing options...
KevinM1 Posted September 17, 2009 Share Posted September 17, 2009 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/174639-function-that-calls-a-class-function-outsid-itself/#findComment-920383 Share on other sites More sharing options...
ozestretch Posted September 17, 2009 Share Posted September 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/174639-function-that-calls-a-class-function-outsid-itself/#findComment-920390 Share on other sites More sharing options...
gladideg Posted September 17, 2009 Author Share Posted September 17, 2009 Nghtslyr: Thank you very much for the help. Someone actually told me this the other day, but I didn't understand until now. ozestretch: We both learned something usefull now ;-) Quote Link to comment https://forums.phpfreaks.com/topic/174639-function-that-calls-a-class-function-outsid-itself/#findComment-920391 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.