本文整理汇总了PHP中static::conn方法的典型用法代码示例。如果您正苦于以下问题:PHP static::conn方法的具体用法?PHP static::conn怎么用?PHP static::conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类static
的用法示例。
在下文中一共展示了static::conn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setConnection
public static function setConnection($config = [])
{
if (static::$conn === null) {
static::$conn = \Doctrine\DBAL\DriverManager::getConnection($config, new \Doctrine\DBAL\Configuration());
}
return static::$conn;
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
$configDir = __DIR__ . '/../../../config';
static::$structure = Structure::createFromYaml($configDir . '/structure.yml');
static::$conn = (require_once $configDir . '/config.php');
static::$mf = new ManagerFactory(static::$conn, static::$structure, true);
}
示例3: __destruct
public function __destruct()
{
if (!is_null(static::$conn)) {
static::$conn->close();
static::$conn = null;
}
}
示例4: connect
/**
* @todo: Нужно переписать, что бы в качестве PDO можно было передать что-то другое - DI
* @return mixed
*/
protected function connect()
{
if (null === static::$conn) {
static::$conn = new \PDO('mysql:host=' . $this->options['host'] . ';' . 'port=' . $this->options['port'] . ';', $this->options['user'], $this->options['password']);
}
return static::$conn;
}
示例5: connect
static function connect()
{
if (!static::$conn) {
static::$conn = mysqli_connect('localhost', getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'));
mysqli_select_db(static::$conn, getenv('MYSQL_DB'));
}
return static::$conn;
}
示例6: getconn
static function getconn()
{
if (!static::$conn) {
static::$conn = new mysqli(static::$servername, static::$username, static::$password, static::$dbname);
if (static::$conn->connect_error) {
die("Connection failed: ");
}
}
return static::$conn;
}
示例7: conn
public static function conn()
{
if (static::$conn === null) {
static::$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array('host' => Config::get('db_host'), 'driver' => 'pdo_mysql', 'user' => Config::get('db_login'), 'password' => Config::get('db_password'), 'dbname' => Config::get('db_name'), 'charset' => 'utf8');
static::$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, static::$config);
static::$conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
}
return static::$conn;
}
示例8: getConn
/**
* @return \Doctrine\DBAL\Connection
* @throws \Doctrine\DBAL\DBALException
* @throws \Exception
*/
public static function getConn()
{
$doctrineConfig = new Configuration();
if (!empty(self::$conf)) {
static::$conn = DriverManager::getConnection(self::$conf, $doctrineConfig);
} else {
throw new \Exception('Configuration problems');
}
return static::$conn;
}
示例9: getConn
/**
* @return \Doctrine\DBAL\Connection
* @throws \Doctrine\DBAL\DBALException
* @throws \Exception
*/
public static function getConn()
{
if (null === static::$conn) {
$doctrineConfig = new Configuration();
$yaml = new Parser();
$config = $yaml->parse(file_get_contents('pabtest-config.yml'));
if (!empty($config['db'])) {
static::$conn = DriverManager::getConnection($config['db'], $doctrineConfig);
} else {
throw new \Exception('Configuration problems');
}
}
return static::$conn;
}
示例10: getInstance
/**
*
Get the only object available
*/
public static function getInstance()
{
//create an object of DBConnection
if (null == static::$conn) {
try {
static::$conn = new PDO(sprintf("mysql:host=%s;dbname=%s", static::$HOSTNAME, static::$DATABASE), static::$USERNAME, static::$PASSWORD);
//enable to throw error,otherwise can't throw error
static::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die;
}
}
return static::$conn;
}
示例11: setUp
/**
* Create database tables required for testing.
*
* @return array array of test data created
*/
public static function setUp()
{
//Load environment variables
$dotenv = new \Dotenv\Dotenv(__DIR__ . '/../../');
if (!getenv('APP_ENV')) {
$dotenv->load();
}
//Create connection and execute schema
static::$conn = new Connection();
Schema::createSchema();
//Add test data to user table if not exist or no errors returned
$user = User::firstOrCreate(['username' => 'test-root', 'password' => hash('SHA256', 'test-root')]);
$emojiData = ['name' => 'Happy Face', 'char' => ':)', 'category' => 'Happy'];
//Build keywords array and create users emojis
$keywords = ['happy', 'face', 'emotion'];
$emoji = $user->emojis()->firstOrCreate($emojiData);
//Add keywords to keywords table
$keyId = [];
foreach ($keywords as $keyword) {
$key = $emoji->keywords()->firstOrCreate(['name' => $keyword]);
$keyId[] = $key->id;
}
return ['userId' => $user->id, 'emojiId' => $emoji->id, 'keywordsId' => $keyId];
}
示例12: Init
/**
* Initializes static fields, including a call to Columns() to get field types.
*/
protected static function Init()
{
if (is_null(static::$table)) {
static::$table = strtolower(get_called_class());
}
if (is_null(static::$conn) && isset($GLOBALS['conn'])) {
static::$conn = $GLOBALS['conn'];
}
if (is_null(static::$cache) && isset($GLOBALS['cache'])) {
static::$cache = $GLOBALS['cache'];
}
if (is_null(static::$columns)) {
static::$columns = static::Columns();
}
}
示例13: __construct
public function __construct($conn)
{
$this->transactionID = rand();
static::$conn = $conn;
}
示例14: __construct
public function __construct($url)
{
if (is_null(static::$config) && isset($GLOBALS['config'])) {
static::$config = $GLOBALS['config'];
}
if (is_null(static::$conn) && isset($GLOBALS['conn'])) {
static::$conn = $GLOBALS['conn'];
}
if (is_null(static::$cache) && isset($GLOBALS['cache'])) {
static::$cache = $GLOBALS['cache'];
}
if (is_null(static::$session) && isset($GLOBALS['session'])) {
static::$session = $GLOBALS['session'];
}
$this->url = $url;
$this->Init();
}
示例15: configureDB
public static function configureDB($dsn, $username, $password)
{
static::$conn = DB::getConnection($dsn, $username, $password);
}