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(); ?> Link to comment https://forums.phpfreaks.com/topic/72805-my-first-class-move-me-to-oop-please-sorry/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.