Mini Shell
<?php
/**
* Database
*
* @author Andrew Esteves <andrew@digitalnativa.com.br>
* @copyright Digital Nativa (www.digitalnativa.com.br)
*/
class DB
{
/**
* @var connection instance
*/
private static $_instance;
/**
* Creates a PDO instance representing a connection to a database
* Singleton
*/
public static function connection()
{
if(!isset(self::$_instance)) {
try {
self::$_instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
self::$_instance->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$_instance->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
return self::$_instance;
}
/**
* Prepares a statement for execution and returns a statement object
*
* @param String $sql
* @return Object
*/
public static function prepare($sql)
{
return self::connection()->prepare($sql);
}
/**
* Returns the ID of the last inserted row or sequence value
*
* @return Int
*/
public static function lastInsertId(){
return self::connection()->lastInsertId();
}
}
Zerion Mini Shell 1.0