Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Adjust the parameters of the database, and to execute queries:
- // $conn = new Connector();
- // $result = $conn->executeQuery("SELECT * FROM TABLENAME");
- class Connector
- {
- private $connection;
- private $hostName;
- private $userName;
- private $password;
- private $database;
- //set the parameter of the database, here, nothing more needs to be modified.
- public function __construct()
- {
- $this->hostName = "localhost";
- $this->userName = "root";
- $this->password = "yourpassword";
- $this->database = "databaseName";
- }
- //this function is used to open the connection between php & sql server
- public function openConnection()
- {
- $this->connection = mysqli_connect($this->hostName,$this->userName,$this->password);
- mysqli_select_db($this->connection , $this->database);
- }
- //this function is used to close the opened connection
- public function closeConnection()
- {
- if (isset($this->connection))
- $this->connection->close();
- }
- //this function is for executing sql queries
- public function executeQuery ( $query )
- {
- $this->openConnection();
- $result = $this->connection->query($query);
- $this->closeConnection();
- return $result;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment