Guest User

Untitled

a guest
Dec 1st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2. // Adjust the parameters of the database, and to execute queries:
  3. // $conn = new Connector();
  4. // $result = $conn->executeQuery("SELECT * FROM TABLENAME");
  5. class Connector
  6. {
  7. private $connection;
  8. private $hostName;
  9. private $userName;
  10. private $password;
  11. private $database;
  12. //set the parameter of the database, here, nothing more needs to be modified.
  13. public function __construct()
  14. {
  15. $this->hostName = "localhost";
  16. $this->userName = "root";
  17. $this->password = "yourpassword";
  18. $this->database = "databaseName";
  19. }
  20. //this function is used to open the connection between php & sql server
  21. public function openConnection()
  22. {
  23. $this->connection = mysqli_connect($this->hostName,$this->userName,$this->password);
  24. mysqli_select_db($this->connection , $this->database);
  25. }
  26. //this function is used to close the opened connection
  27. public function closeConnection()
  28. {
  29. if (isset($this->connection))
  30. $this->connection->close();
  31. }
  32. //this function is for executing sql queries
  33. public function executeQuery ( $query )
  34. {
  35. $this->openConnection();
  36. $result = $this->connection->query($query);
  37. $this->closeConnection();
  38. return $result;
  39. }
  40. }
  41. ?>
Add Comment
Please, Sign In to add comment