Advertisement
Guest User

Untitled

a guest
Sep 10th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?
  2.  
  3. $database_host = "127.0.0.1";
  4. $database_user = "x";
  5. $database_pass = "x";
  6. $database_name = "x";
  7.  
  8. $db = new database($database_host, $database_user, $database_pass, $database_name);
  9.  
  10. class database {
  11.  
  12. var $link, $result;
  13.  
  14. function database($host, $user, $pass, $db) {
  15. $this->link = mysqli_connect($host, $user, $pass) or $this->error();
  16. mysqli_select_db($this->link, $db) or $this->error();
  17. }
  18.  
  19. function query($query) {
  20. $this->result = mysqli_query($this->link, $query) or $this->error();
  21. $this->_query_count++;
  22. return $this->result;
  23. }
  24. function countRows($result = "") {
  25. if ( empty( $result ) )
  26. $result = $this->result;
  27. return mysqli_num_rows($result);
  28. }
  29. function fetch($result = "") {
  30. if ( empty( $result ) )
  31. $result = $this->result;
  32. return mysqli_fetch_array($this->link, $result);
  33. }
  34. function fetch_num($result = "") {
  35. if ( empty( $result ) )
  36. $result = $this->result;
  37. return mysqli_fetch_array($result, MYSQLI_NUM);
  38. }
  39. function fetch_assoc($result = "") {
  40. if ( empty( $result ) )
  41. $result = $this->result;
  42. return mysqli_fetch_array($result, MYSQLI_ASSOC);
  43. }
  44. function escape($str) {
  45. return mysqli_real_escape_string($this->link, $str);
  46. }
  47. function error() {
  48. if ( $_GET["debug"] == 1 ){
  49. die(mysqi_error());
  50. } else {
  51. echo "Error in db code";
  52. }
  53. }
  54. }
  55.  
  56.  
  57.  
  58. function sanitize($data) {
  59.  
  60. // apply stripslashes if magic_quotes_gpc is enabled
  61. //if(get_magic_quotes_gpc())
  62. // $data = stripslashes($data);
  63.  
  64. // a mysqli connection is required before using this function
  65. //$data = trim(mysqli_real_escape_string($data));
  66.  
  67. return $data;
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement