Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. class db_system
  2. {
  3. private $link;
  4. private $result;
  5.  
  6. /*
  7. Constructor connects to database and store in link
  8. */
  9. public function __construct()
  10. {
  11. $lines = file('../../secret/topsecret');
  12. $this->link = mysqli_connect(trim($lines[0]), trim($lines[1]), trim($lines[2]), trim($lines[3])) or die("Could not connect to " . mysqli_error($this->link));
  13. if(is_resource($this->link))
  14. echo "true";
  15. else
  16. echo "false"; // it always prints false;
  17. }
  18.  
  19. /*
  20. this method process the query and returns the result od the query
  21. */
  22. public function sqlquery($query)
  23. {
  24. $this->result = mysqli_query($this->link, $query) or die('query failed ' . mysqli_error($this->link));
  25. }
  26.  
  27. /*
  28. this method returns the rows in an array form
  29. */
  30. public function get_data()
  31. {
  32. return mysqli_fetch_array($this->result);
  33. }
  34.  
  35. /*
  36. destructor closes sql connection if link is active
  37. */
  38. public function __destruct()
  39. {
  40. if($this->link)
  41. {
  42. mysqli_close($this->link);
  43. }
  44. }
  45.  
  46. public function getlink()
  47. {
  48. return $this->link;
  49. }
  50. }
  51.  
  52. include 'library.php';
  53.  
  54. $view = new db_system(); // connection object made
  55.  
  56. $per = "%";
  57.  
  58. $qry = sprintf('SELECT * FROM inventory WHERE description LIKE "%s%s%s"',$per,mysql_real_escape_string($find,$view->getlink()),$per);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement