Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------
- connect.php
- ------------------------------------------
- <?php
- /*****************
- *
- * Connect to MySQL
- * Author: codekK
- *
- *****************/
- class DBconfig {
- private $conn = null;
- private $server = "server"; // Server MySQL
- private $user = "user"; // Username MySQL
- private $pass = "pass"; // Password MySQL
- private $db = "db"; // DB MySQL
- public function newConn(){
- // Setting up connection
- if(!isset($this->conn)){
- try {
- $this->conn = new PDO("mysql:dbname={$this->db};host={$this->server}",$this->user,$this->pass);
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // Error
- } catch (PDOException $e){
- return false;
- }
- }
- return $this->conn;
- }
- }
- ?>
- ------------------------------------------
- index.php
- ------------------------------------------
- <html>
- <head>
- <title>Hello</title>
- </head>
- <body>
- <h1>Hello</h1>
- <?php
- require_once("connect.php");
- $db = new DBconfig();
- $conn = $db->newConn();
- $query = $conn->prepare("SELECT usuario FROM users_liberaciones");
- while ($row = $query->fetch()):
- echo $row['usuario'];
- endwhile;
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment