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); } } ?> 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 } 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) 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 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 Link to comment https://forums.phpfreaks.com/topic/140291-class/#findComment-734079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.