本文整理汇总了PHP中Connection::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::instance方法的具体用法?PHP Connection::instance怎么用?PHP Connection::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public static function get()
{
if (is_null(self::$instance)) {
self::$instance = self::openConnection();
}
return self::$instance;
}
示例2: getInstance
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new Connection();
}
return self::$instance;
}
示例3: get_instance
/**
* Get a singleton instance of Connection<object>
*
* @return Connection
*/
public static function get_instance()
{
if (self::$instance === null) {
self::$instance = new Connection();
}
return self::$instance;
}
示例4: open
public static function open()
{
if (self::$instance == null) {
$klass = __CLASS__;
self::$instance = new $klass('localhost', 'root', "", 'impaz');
}
return self::$instance;
}
示例5: getInstance
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new self(self::HOST, self::USER, self::PASSWORD, self::DATABASE);
self::$instance->query("SET NAMES 'utf8'");
}
return self::$instance;
}
示例6: instance
public static function instance()
{
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c();
}
return self::$instance;
}
示例7: getInstance
public static function getInstance()
{
if (!isset(self::$instance)) {
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
self::$instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_SCHEMA, DB_USERNAME, DB_PASSWORD, $pdo_options);
}
return self::$instance;
}
示例8: get_connection
/**
* If $name is null then the default connection will be returned.
*
* @see Config
* @param string $name Optional name of a connection
* @return Connection
*/
public static function get_connection($name = null)
{
$config = Config::instance();
$name = $name ? $name : $config->get_default_connection();
if (!isset(self::$connections[$name]) || !self::$connections[$name]->connection) {
self::$connections[$name] = Connection::instance($config->get_connection($name));
}
return self::$connections[$name];
}
示例9: __construct
private function __construct()
{
try {
self::$instance = new PDO('mysql:host=localhost;port=3306;dbname=biblioteca;charset=utf8', 'root', 'qwe123');
self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Erro no banco de dados: " . $e->getMessage());
}
}
示例10: __construct
/**
* Constuctor de la clase haciendo uso del patrón Singletón
* @return Connection
*/
public function __construct()
{
if (!self::$instance) {
$this->loadProxyMySql();
$this->loadProxySoap();
self::$instance = $this;
}
return self::$instance;
}
示例11: remove
public function remove($table, $columns, $options = array())
{
$name = $this->getName($columns, $options);
if ($name === 'PRIMARY') {
$sql = "ALTER TABLE `{$table}` DROP PRIMARY KEY";
} else {
$sql = "ALTER TABLE `{$table}` DROP INDEX `{$name}`";
}
return Connection::instance()->execute($sql);
}
示例12: __construct
private function __construct()
{
try {
Connection::$instance = new PDO("mysql:host={$this->servername};dbname={$this->dbName}", $this->username, $this->password);
// set the PDO error mode to exception
Connection::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
示例13: getInstance
/**
* Singleton method that requests a unique instance of the class
*
* @return object (PDO)
* @access public
*/
public static function getInstance()
{
if (!self::$instance instanceof self) {
try {
self::$instance = new self();
self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
return self::$instance;
}
示例14: getInstance
public static function getInstance()
{
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;
}
示例15: remove
public function remove($table)
{
return Connection::instance()->execute("DROP TABLE `{$table}`");
}