本文整理汇总了PHP中Db::db方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::db方法的具体用法?PHP Db::db怎么用?PHP Db::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
public static function open($config)
{
self::$db = @mysql_connect($config['hostname'], $config['username'], $config['password']);
if (self::$db) {
@mysql_select_db($config['database']);
}
}
示例2: connect
/**
* Abre la conexión.
* La configuración debería contener los siguientes campos:
* hostname = equipo a cual conectarse
* username = usuario
* password = clave de acceso
* database = nombre de la base de datos
*
* @param array $config
*/
public static function connect($config)
{
self::$db = @new mysqli($config['hostname'], $config['username'], $config['password'], $config['database']);
if (self::$db->connect_errno) {
throw new Exception(self::$db->connect_error, self::$db->connect_errno);
}
}
示例3: getInstance
public static function getInstance($option = null)
{
if (self::$db == null) {
self::$db = new Db($option);
}
return self::$db;
}
示例4: getInstance
public static function getInstance()
{
if (!self::$db) {
self::$db = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbName . ';port=' . self::$port, self::$user, self::$pass);
}
return self::$db;
}
示例5: __d
/**
* A Singleton pattern
* to prevent multiple use of db
* @return object
*/
public static function __d()
{
if (!isset($db)) {
self::$db = new Db();
}
return self::$db;
}
示例6: init
public static function init()
{
$mongo = new Mongo();
self::$db = $db = $mongo->poggin;
self::$songs = $db->songs;
self::$users = $db->users;
}
示例7: __construct
private function __construct()
{
try {
self::$db = new \PDO("mysql:host=" . DbConfig::DB_HOST . ";dbname=" . DbConfig::DB_NAME, DbConfig::DB_USER, DbConfig::DB_PASS);
self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $e) {
echo "Connection Error: " . $e->getMessage();
}
}
示例8: switchDb
/**
* 切换使用的DB连接
* @param string $sign
*/
public static function switchDb($sign = 'default')
{
if (isset(self::$connectList[$sign])) {
self::$db = self::$connectList[$sign];
return self::_db();
} else {
return false;
}
}
示例9: getInstance
public static function getInstance()
{
//static = geen object nodig om aan te roepen
if (self::$db != null) {
return self::$db;
} else {
self::$db = new PDO('mysql:host=localhost; dbname=kangu-product', 'root', 'root');
return self::$db;
}
}
示例10: dbConnect
/**
* singleton pattern to return single db handle
*
* @param string db host
* @param string db name
* @param string db user
* @param string db password
* @return handle database handle
*/
protected static function dbConnect($dbHost, $dbName, $dbUser, $dbPassword)
{
if (!self::$db) {
try {
self::$db = new PDO('mysql:host=' . $dbHost . ';dbname=' . $dbName, $dbUser, $dbPassword);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return self::$db;
} catch (PDOException $e) {
echo '<br />' . __FUNCTION__ . ' in ' . __FILE__ . ' at ' . __LINE__ . ': ' . $e->getMessage() . '<br /><br />';
}
}
}
示例11: change_db
public static function change_db($db)
{
global $dbdata;
if ($db != '') {
Db::$dbconn = $db;
Db::$db = $dbdata[$db]['dbtype'];
$conn = Db::conn_db($dbdata);
Db::$conn = $conn;
} else {
echo "Sila semak pilihan pangkalan data";
}
}
示例12: dbConnect
/**
* Database connector
*/
private function dbConnect()
{
try {
// open connection to MongoDB server
$connect = new \Mongo();
// access database
Db::$db = $connect->{Db::DB_NAME};
} catch (\MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (\MongoException $e) {
die('Error: ' . $e->getMessage());
}
}
示例13: init
public static function init()
{
if (!self::$db) {
try {
$dsn = "mysql:host=" . Config::$db_host . ";dbname=" . Config::$db_name . ";charset=utf8";
self::$db = new PDO($dsn, Config::$db_user, Config::$db_pass);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit("Connection error: " . $e->getMessage());
}
}
return self::$db;
}
示例14: init
public static function init()
{
if (!self::$db) {
try {
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;
self::$db = new PDO($dsn, DB_USER, DB_PASS);
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die('Connection error: ' . $e->getMessage());
}
}
return self::$db;
}
示例15: init
public static function init()
{
if (!self::$db) {
try {
$cfg = Configuracion::getConfiguracion('basedatos');
$dsn = $cfg['dsn'];
self::$db = new PDO($dsn, $cfg['usuario'], $cfg['clave']);
//Crea un nuevo objeto PDO (PHP Data Object)
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Indica que lanza una excepción si existe algún error.
self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//Establece la propiedad de asociacion para los resultados
// de consulta
} catch (PDOException $exc) {
die('Error de conexion a la base de datos! ' . $exc->getMessage());
}
}
return self::$db;
}