Ejemplo n.º 1
0
 public static final function GetInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 /**
  * @return resource mysql connection
  */
 public static function GetConnection()
 {
     if (!self::$conn) {
         self::$conn = new \PDO("mysql:host=" . self::DBHOST . ";dbname=" . self::DBNAME . ";", self::DBUSER, self::DBPASS);
     }
     return self::$conn;
 }
Ejemplo n.º 3
0
 /**
  * Create new DB instance.
  */
 public function __construct()
 {
     if (!self::$dbh) {
         parent::__construct();
         $db_string = 'dbname=' . $this->dbname;
         $dsn = 'mysql:host=' . $this->host . ';' . $db_string;
         try {
             self::$dbh = new PDO($dsn, $this->user, $this->pass);
             self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             echo 'Connection failed: ' . $e->getMessage();
         }
     }
 }
Ejemplo n.º 4
0
<?php

header('Content-disposition: attachment; filename=dump.txt');
header('Context-type: text/csv');
class AppDB extends SQLite3
{
    function __construct()
    {
        $this->open('005.db');
    }
}
$db = new AppDB();
if (!$db) {
    echo "Failed to open DB";
    return;
}
$query = "SELECT * FROM apps";
$results = $db->query($query);
$output = fopen('php://output', 'w');
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
    fputcsv($output, $row);
    echo "\n";
}
Ejemplo n.º 5
0
<?php

class AppDB extends SQLite3
{
    function __construct()
    {
        $this->open('005.db');
    }
}
$db = new AppDB();
if (!$db) {
    echo "Failed to open DB";
    return;
}
function gvar($ar)
{
    if (isset($_POST[$ar]) && $_POST[$ar] !== '') {
        return "'" . SQLite3::escapeString($_POST[$ar]) . "'";
    } else {
        return 'NULL';
    }
}
$uname = gvar('username');
$mail = gvar('email');
$st = gvar('state');
$cty = gvar('city');
$zp = gvar('zip');
$comment = gvar('comments');
$dt = gvar('date');
$query = "INSERT INTO apps (username,email,city,state,zip,comments,date) VALUES (" . $uname . "," . $mail . "," . $cty . "," . $st . "," . $zp . "," . $comment . "," . $dt . ");";
$results = $db->query($query);
Ejemplo n.º 6
0
<?php

//Connects to the database
//Load database config
include APPLICATION_CONFDIR . 'db.conf.php';
//Verify database connectivity
$DB = AppDB::GetInstance();
if (!$DB->ping()) {
    //Connection failure
    die("Database Error");
    exit;
}