示例#1
0
文件: db.php 项目: jask0/hh_gbook
 public function __construct()
 {
     global $dbc;
     //read from config.php
     $c = new CONNECT();
     $this->conn = $c->getConnection();
     $this->table_posts = $dbc['table'] . "posts";
     $this->table_config = $dbc['table'] . "config";
 }
示例#2
0
<?php

require_once 'config.php';
class CONNECT
{
    public $conn;
    public function __construct()
    {
        global $dbc;
        $this->conn = mysqli_connect($dbc['servername'], $dbc['username'], $dbc['password'], $dbc['dbname']);
    }
    public function getConnection()
    {
        return $this->conn;
    }
}
if (isset($dbc)) {
    // Create connection
    $db = new CONNECT();
    // Check connection
    if (!$db->getConnection()) {
        die("Connection failed: " . mysqli_connect_error());
    }
}