本文整理汇总了PHP中DBConnection::build方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::build方法的具体用法?PHP DBConnection::build怎么用?PHP DBConnection::build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::build方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __toString
{
use \FW\DI\DI;
public $id;
public $title;
public $content;
protected $table = 'post';
public function __toString()
{
return "Model_Post ({$this->table}) {$this->id}";
}
public function setId($i)
{
$this->id = $i;
}
}
$dbCon = DBConnection::build()->with(['host' => 'localhost', 'user' => 'root', 'password' => 'pwd']);
$model = Model_Post::build()->with($dbCon);
var_dump($dbCon->isConnected());
// true
var_dump($model);
$model->id = 42;
var_dump($model->id);
// 42
var_dump((string) $model);
// Model_Post (post) 42
var_dump(isset($model->title));
// false
var_dump($model->title);
// null
var_dump("#### Immutable");
// Once build it can't be changed externally
示例2: __construct
protected $user;
protected $password;
public function __construct($host)
{
}
}
class DBExtend extends DBConnection
{
}
class Model
{
use \FW\DI\DI;
protected $connection = DBExtend::class;
protected $table;
public function __construct($connection)
{
}
public function hello()
{
return 'hello';
}
}
$model = Model::build()->with(DBExtend::build()->with('localhost', 'host'));
echo $model->hello() . "\n";
try {
$model = Model::build()->with(DBConnection::build()->with('localhost', 'host'));
// This will fail
echo $model->hello() . "\n";
} catch (Exception $e) {
var_dump($e->getMessage());
}
示例3: error_reporting
<?php
require __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL);
class DBConnection
{
use \FW\DI\DI;
protected $host;
protected $user;
protected $password;
public function __construct($host, $user, $password)
{
}
public function isConnected()
{
return true;
}
}
// As an array of named parameters
$dbCon = DBConnection::build()->with(['host' => 'localhost', 'user' => 'root', 'password' => 'pwd']);
// OR a list of chained parameters
$dbCon = DBConnection::build()->with('localhost', 'host')->with('root', 'user')->with('pwd', 'password');
var_dump($dbCon);
示例4: error_reporting
<?php
require __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL);
class DBConnection
{
use \FW\DI\DI;
protected $host;
public function __construct($host)
{
}
public function hello()
{
return 'hello';
}
}
$model = DBConnection::build()->with('localhost', 'host');
echo $model->hello() . "\n";
try {
$model->with('test', 'host');
// This will fail
echo $model->hello() . "\n";
} catch (Exception $e) {
var_dump($e->getMessage());
}
示例5: __construct
{
}
}
class DBConnection
{
use \FW\DI\DI;
public $host;
public function __construct($host)
{
}
}
class Model
{
use \FW\DI\DI;
public $connection = DBConnection::class;
public $dependancy = Dependancy::class;
public function __construct($connection, $dependancy)
{
}
}
\FW\DI\AutoBuild::register(Dependancy::class, ['name' => 'AutoName']);
\FW\DI\AutoBuild::register(DBConnection::class, ['host' => 'localhost']);
// $dependancy will be autoloaded since it's registered already
try {
$post = Model::build()->auto();
var_dump($post->connection->host);
$overridenPost = Model::build()->with(DBConnection::build()->with('127.0.0.1', 'host'), 'connection')->auto();
var_dump($overridenPost->connection->host);
} catch (Exception $e) {
var_dump($e->getMessage());
}