xtremey_ytinasni Posted January 12, 2012 Share Posted January 12, 2012 Would this be a decent class to use, or is there anything I should add,edit, or remove? <?php /** * MySQL Database Class * * @author: Dillion DeWitt * @copyright: Dillion DeWitt (c), 2012. */ class DB { var $link; var $host; var $user; var $password; var $database; var $query; var $result; var $debug=false; function connect($host,$user,$pass,$database=false,$persistent=false){ //Assign values to class variables. $this->host = $host; $this->user = $user; $this->password = $pass; if( $persistent ){ $this->link = mysql_pconnect($host,$user,$pass); } else { $this->link = mysql_connect($host,$user,$pass); } if( $database ){ $this->database = $database; mysql_select_db($database,$this->link); } } function isConnected(){ if(mysql_ping($this-link) === true){ $msg = 'Connected.'; } else { $msg = 'Disconnected.'; } return $msg; } function query($sql){ $this->query = $sql; $this->result = mysql_query($sql, $this->link) or $this->Error(); } function num_rows($result){ $result = $this->result; return mysql_num_rows($result); } function get_single($result){ $result = $this->result; return mysql_fetch_row($result); } function get_rows($result){ $result = $this->result; return mysql_fetch_assoc($result); } function Error(){ if($this->debug){ echo mysql_errno().': '.mysql_error(); exit; } else { echo 'An error has occured.'; exit; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/ Share on other sites More sharing options...
KevinM1 Posted January 13, 2012 Share Posted January 13, 2012 Why reinvent the wheel? Look at: mysqli pdo Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/#findComment-1307091 Share on other sites More sharing options...
scootstah Posted January 13, 2012 Share Posted January 13, 2012 Why reinvent the wheel? Look at: mysqli pdo Because they both have annoyingly long syntax. Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/#findComment-1307094 Share on other sites More sharing options...
xtremey_ytinasni Posted January 13, 2012 Author Share Posted January 13, 2012 My reason for creating this simple little class is because it just makes it kind of easier... I'm also creating a Validation class and will be posting it shortly for review... Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/#findComment-1307095 Share on other sites More sharing options...
KevinM1 Posted January 13, 2012 Share Posted January 13, 2012 Why reinvent the wheel? Look at: mysqli pdo Because they both have annoyingly long syntax. Then write a wrapper? Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/#findComment-1307097 Share on other sites More sharing options...
sandeep529 Posted January 13, 2012 Share Posted January 13, 2012 are you looking for something like this.. http://www.phpclasses.org/browse/file/26537.html This class I made specifically to shorten syntax for Database operations... Quote Link to comment https://forums.phpfreaks.com/topic/254924-database-class/#findComment-1307134 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.