本文整理汇总了PHP中ActiveRecord::setDb方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::setDb方法的具体用法?PHP ActiveRecord::setDb怎么用?PHP ActiveRecord::setDb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::setDb方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInit
public function testInit()
{
@unlink('test.db');
ActiveRecord::setDb(new PDO('sqlite:test.db'));
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user (\n id INTEGER PRIMARY KEY, \n name TEXT, \n password TEXT \n );");
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS contact (\n id INTEGER PRIMARY KEY, \n user_id INTEGER, \n email TEXT,\n address TEXT\n );");
}
示例2: connectDb
public function connectDb($config)
{
/**
* Это, конечно, не самое красивое решение, но лучше уж написать код
* проще, чем вводить какие-нибудь там конфиги только для одного-един-
* ственного файла.
*/
$c = (include PATH_APPLICATION . '/config/' . $config);
$this->mysqli = new MysqliE($c['hostname'], $c['username'], $c['password'], $c['database']);
if ($this->mysqli->connect_error) {
throw new Exception('Connect error:' . $this->mysqli->connect_error);
}
ActiveRecord::setDb($this->mysqli);
return $this;
}
示例3: array
include "ActiveRecord.php";
//include "ActiveRecord.min.php";
class User extends ActiveRecord
{
public $table = 'user';
public $primaryKey = 'id';
public $relations = array('contacts' => array(self::HAS_MANY, 'Contact', 'user_id'), 'contact' => array(self::HAS_ONE, 'Contact', 'user_id', 'where' => '1', 'order' => 'id desc'));
}
class Contact extends ActiveRecord
{
public $table = 'contact';
public $primaryKey = 'id';
public $relations = array('user' => array(self::BELONGS_TO, 'User', 'user_id'));
}
ActiveRecord::setDb(new PDO('sqlite:test.db', null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)));
try {
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user (");
ActiveRecord::execute("select * from aaa");
} catch (Exception $e) {
var_export($e);
}
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tname TEXT, \n\t\t\t\tpassword TEXT \n\t\t\t);");
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS contact (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tuser_id INTEGER, \n\t\t\t\temail TEXT,\n\t\t\t\taddress TEXT\n\t\t\t);");
$user = new User();
$user->name = 'demo';
$user->password = md5('demo');
var_dump($user->insert());
$contact = new Contact();
$contact->address = 'test';
$contact->email = 'test1234456@domain.com';
示例4: array
//include "ActiveRecord.php";
include "ActiveRecord.min.php";
class User extends ActiveRecord
{
public $table = 'user';
public $primaryKey = 'id';
public $relations = array('contacts' => array(self::HAS_MANY, 'Contact', 'user_id'), 'contact' => array(self::HAS_ONE, 'Contact', 'user_id', 'where' => '1', 'order' => 'id desc'));
}
class Contact extends ActiveRecord
{
public $table = 'contact';
public $primaryKey = 'id';
public $relations = array('user' => array(self::BELONGS_TO, 'User', 'user_id'));
}
ActiveRecord::setDb(new PDO('sqlite:test.db'));
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS user (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tname TEXT, \n\t\t\t\tpassword TEXT \n\t\t\t);");
ActiveRecord::execute("CREATE TABLE IF NOT EXISTS contact (\n\t\t\t\tid INTEGER PRIMARY KEY, \n\t\t\t\tuser_id INTEGER, \n\t\t\t\temail TEXT,\n\t\t\t\taddress TEXT\n\t\t\t);");
/*
$user = new User();
$user->name = 'demo';
$user->password = md5('demo');
var_dump($user->insert());
$contact = new Contact();
$contact->address = 'test';
$contact->email = 'test1234456@domain.com';
$contact->user_id = $user->id;
var_dump($contact->insert());
*/
/*