Aureole Posted October 11, 2007 Share Posted October 11, 2007 EDIT: Crap, wrong Forum... and I forgot to edit out my MYSQL connection details... *goes to change username and password*, please don't hack me kthx... Hey I'm wondering if I'm going about things in the right way so far... I made a db class... here's what I have so far... <?php class database { var $db_host; var $db_user; var $db_pass; var $db_name; var $db_connect; var $db_disconnect; var $db_select; var $result; var $output; var $snr_from; function connect() { $this->db_host = 'localhost'; $this->db_user = ''; $this->db_pass = ''; $this->db_name = ''; $this->db_connect = mysql_connect($this->db_host, $this->db_user, $this->db_pass); $this->db_select = mysql_select_db($this->db_name); if($this->db_connect) { $this->output = 'mysql_connect() success.<br />'; } else { $this->output = 'mysql_connect() failure.<br />'; } if($this->db_select) { $this->output .= 'mysql_select_db() success.<br />'; } else { $this->output .= 'mysql_select_db() failure.<br />'; } echo $this->output; } function disconnect() { $this->db_disconnect = mysql_close($this->db_connect) or die('Error closing DB Connection.<br />'); if($this->db_disconnect) { $this->output = 'mysql_close() success.<br />'; } else { $this->output = 'mysql_close() failure.<br />'; } echo $this->output; } function simple_num_rows($snr_from) { $this->snr_from = $snr_from; $query = "SELECT * FROM $this->snr_from"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); $this->output = $num_rows; return $this->output; } } ?> <?php // Usage example. $swr3->database = new database; $swr3->database->connect(); $swr3->database->simple_num_rows('members'); echo $swr3->database->output .' Members<br />'; $swr3->database->simple_num_rows('topics'); echo $swr3->database->output .' Topics<br />'; $swr3->database->simple_num_rows('replies'); echo $swr3->database->output .' Replies<br />'; $swr3->database->disconnect(); ?> Quote Link to comment 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.