本文整理汇总了PHP中Db::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::connection方法的具体用法?PHP Db::connection怎么用?PHP Db::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
protected static function getConnection()
{
if (!self::$connection) {
self::$connection = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
}
return self::$connection;
}
示例2: getInstance
public static function getInstance()
{
if (!self::$connection) {
self::$connection = new self();
}
return self::$connection;
}
示例3: getTermInfo
public function getTermInfo($condition)
{
$db = Db::connection($this->connection)->table($this->table);
$db = $this->formatCondition($db, $condition);
$res = $db->first();
return $res;
}
示例4: connect
public static function connect($host, $database, $user, $password)
{
if (!isset(self::$connection)) {
$dsn = "mysql:host={$host};dbname={$database}";
self::$connection = new PDO($dsn, $user, $password, self::$options);
}
}
示例5: connect
public static function connect($config)
{
self::$connection = @new mysqli($config['hostname'], $config['username'], $config['password'], $config['database']);
if (self::$connection->connect_errno) {
throw new Exception(self::$connection->connect_error);
}
self::execute("SET NAMES 'utf8'");
}
示例6: connect
public static function connect($host, $user, $password, $database)
{
if (!isset(self::$connection)) {
self::$connection = @new PDO("mysql:host={$host};dbname={$database}", $user, $password, self::$settings);
return true;
}
return false;
}
示例7: connect
public function connect()
{
if (!isset(self::$connection)) {
self::$connection = new mysqli('localhost', "root", "", "gotit");
}
if (self::$connection === false) {
return false;
}
return self::$connection;
}
示例8: connect
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect()
{
if (!isset(self::$connection)) {
$config = parse_ini_file('../config/config.ini');
self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
}
if (self::$connection === false) {
return false;
}
return self::$connection;
}
示例9: connect
public function connect()
{
if (!isset(self::$connection)) {
$login = $this->readLogin("../../config.json");
self::$connection = new mysqli($login["hostname"], $login["username"], $login["password"], $login["db"]);
}
if (self::$connection->connect_errno) {
echo "Failed to connect to MySQL: " . self::$connection->connect_error;
return false;
}
return self::$connection;
}
示例10: connect
/**
* Connect to database.
*/
public static function connect()
{
self::$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
if (!self::$connection) {
trigger_error('Can\'t connect to database.');
return false;
} else {
mysql_select_db(DB_DATABASE);
mysql_query("SET CHARACTER SET " . MYSQL_CHARSET);
return true;
}
}
示例11: connect
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect()
{
// Try and connect to the database
if (!isset(self::$connection)) {
self::$connection = new mysqli(global_mysql_server, global_mysql_user, global_mysql_password, global_mysql_database);
}
// If connection was not successful, handle the error
if (self::$connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
return self::$connection;
}
示例12: connect
public function connect()
{
if (!isset(self::$connection)) {
self::$connection = new mysqli(\DbConfig::HOST, \DbConfig::USER_NAME, \DbConfig::USER_PASSWORD, \DbConfig::DB_NAME);
}
//If connection was not success, handle the error
if (!self::$connection) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
self::$connection->autocommit(false);
return self::$connection;
}
示例13: connect
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect()
{
// Try and connect to the database
if (!isset(self::$connection)) {
// Load configuration as an array. Use the actual location of your configuration file
self::$connection = new mysqli('localhost', 'root', 'root', 'servicioslegales');
}
// If connection was not successful, handle the error
if (self::$connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
return self::$connection;
}
示例14: connect
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect()
{
// Try and connect to the database
if (!isset(self::$connection)) {
// Load configuration as an array. Use the actual location of your configuration file
// Put the configuration file outside of the document root
self::$connection = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
}
// If connection was not successful, handle the error
if (self::$connection === false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return false;
}
return self::$connection;
}
示例15: connect
public function connect()
{
// Try and connect to the database, if a connection has not been established yet
if (!isset(self::$connection)) {
// Load configuration
self::$connection = mysqli_connect(host, user, pass, dbname) or die("no connection");
mysqli_select_db(self::$connection, 'moviefy');
}
// If connection was not successful, handle the error
if (self::$connection === false) {
//Handle Error - notify admin
return mysqli_connect_error($connection);
}
return self::$connection;
}