当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveRecord::setDb方法代码示例

本文整理汇总了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        );");
 }
开发者ID:bephp,项目名称:activerecord,代码行数:7,代码来源:ActiveRecordTest.php

示例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;
 }
开发者ID:ruyozora,项目名称:Test-test,代码行数:15,代码来源:Application.php

示例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';
开发者ID:cgslivre,项目名称:activerecord,代码行数:30,代码来源:test.php

示例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());
*/
/*
开发者ID:ruziyi,项目名称:activerecord,代码行数:30,代码来源:test.php


注:本文中的ActiveRecord::setDb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。