Advertisement
Guest User

Untitled

a guest
May 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2. class mysqldb {
  3. //set up the class
  4. var $dbhost;
  5. var $db;
  6. var $dbuser;
  7. var $dbpassword;
  8. var $sql;
  9. var $result;
  10. var $numberrows;
  11. var $dbconnection = false;
  12. var $insert_id;
  13.  
  14. function get_insert_id(){ $this->insert_id=mysql_insert_id(); return $this->insert_id;}
  15.  
  16. function getdb(){return $this->db;}
  17.  
  18. function setdb($req_db){$this->db = $req_db;}
  19.  
  20. function setdbuser($req_user){$this->dbuser = $req_user;}
  21.  
  22. function setdbpassword($req_password){$this->dbpassword = $req_password;}
  23.  
  24. function getsql(){return $this->sql;}
  25.  
  26. function setsql($req_sql) {$this->sql = $req_sql;}
  27.  
  28. function getnumberrows() {return $this->numberrows;}
  29.  
  30. function setnumberrows($req_numberrows) {$this->numberrows = $req_numberrows;}
  31.  
  32. function setdbconnection($req_dbconnection){$this->dbconnection = $req_dbconnection;}
  33.  
  34. function closedbconnection(){
  35. if($this->dbconnection=$TRUE) mysql_close($this->dbconnection);
  36. }
  37.  
  38. function real_escape($string) {
  39. return mysql_real_escape_string($string,$this->dbconnection);
  40. }
  41.  
  42. function mysqldb(){
  43. $HOST = "localhost";
  44. $DB = "your_db_name";
  45. $WEBUSER = "your_mysql_username";
  46. $WEBPASSWORD = "your_mysql_password";
  47. $this->setdb($DB);
  48. $this->setdbuser($WEBUSER);
  49. $this->setdbpassword($WEBPASSWORD);
  50. $this->opendbconnection();
  51. }
  52.  
  53. function opendbconnection(){
  54. $this->dbconnection=mysql_connect("$this->dbhost","$this->dbuser","$this->dbpassword");
  55. if ($this->dbconnection)//if we have connected select and return true
  56. {
  57. mysql_select_db($this->db,$this->dbconnection) or die("Unable to select database");
  58. }
  59. else {$this->dbconnection=false;}
  60.  
  61. // unset the data so it couldn't be dumped
  62. $this->dbhost='';
  63. $this->db='';
  64. $this->dbuser='';
  65. $this->dbpassword='';
  66. }
  67.  
  68. function selectquery(){
  69. $this->qry=@mysql_query($this->sql,$this->dbconnection);
  70. if(!$this->qry){$this->numberrows=0; return false;}//query error
  71.  
  72. else{//query passed
  73. $this->numberrows=@mysql_numrows($this->qry);
  74. //if we have any result fill in the result array
  75. if($this->numberrows>=0) {
  76. for($x=0;$x<$this->numberrows;$x++){$this->result[$x]=@mysql_fetch_array($this->qry);} return true; } else{$this->numberrows=0; return false;}//if we don't have results give error }//end query passed } }//end of class mysqldb ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement