Andy-H Posted January 10, 2009 Share Posted January 10, 2009 This class works fine; I was just wondering if I am using it right and if there is any way to operate on multiple queries with one instance of the class. ??? <?php class db { var $host; var $user; var $pass; var $DB; function db($host = 'localhost', $user = '*******', $pass = '*******', $DB = '*******') { $conn = mysql_connect($host, $user, $pass); $db = mysql_select_db($DB, $conn); } function query($str) { $this->query = mysql_query($str)or die('Query failed on line ' . __LINE__); } function num() { return mysql_num_rows($this->query); } function fetch($type = 'row') { return mysql_fetch_row($this->query); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140291-class/ Share on other sites More sharing options...
ILMV Posted January 10, 2009 Share Posted January 10, 2009 Is this what you mean? $db = new db; $sales=$db->query('SELECT * FROM sales'); while ($row = mysql_fetch_assoc($sales)) { // Do something } // Call $result whatever you want $staff=$db->query('SELECT * FROM staff'); while ($row = mysql_fetch_assoc($staff)) { // Do something } Quote Link to comment https://forums.phpfreaks.com/topic/140291-class/#findComment-734066 Share on other sites More sharing options...
Andy-H Posted January 10, 2009 Author Share Posted January 10, 2009 Yeh lol TY I didn't think it would work that way BTW your quote under your picture is missing the ? (<php) Quote Link to comment https://forums.phpfreaks.com/topic/140291-class/#findComment-734071 Share on other sites More sharing options...
ILMV Posted January 10, 2009 Share Posted January 10, 2009 Lol, cheers mate Quote Link to comment https://forums.phpfreaks.com/topic/140291-class/#findComment-734075 Share on other sites More sharing options...
Andy-H Posted January 10, 2009 Author Share Posted January 10, 2009 NP Quote Link to comment https://forums.phpfreaks.com/topic/140291-class/#findComment-734079 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.