Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // database named : ' php_tut '
- // connection to database : Object-Oriented Programming
- class connectDb{
- private $serverNme = "localhost";
- private $dbName = "php_tut";
- private $dbUser = "root";
- private $dbPassword = "";
- private $conn = false;
- function connect(){
- try{
- $this->conn = new PDO("mysql:host=$this->serverNme;dbname=$this->dbName",
- $this->dbUser,$this->dbPassword);
- return $this->conn;
- }catch(PDOException $e){
- echo "error" . $e->getMessage();
- }
- }
- function disconnect(){ // you will need this function later to close connection
- $this->conn = NULL;
- return $this->conn;
- }
- }
- $connection = new connectDb();
- echo $connection->connect();
Advertisement
Add Comment
Please, Sign In to add comment