Asf_Db_AbstractAdapter::__call

如果Asf框架封装的DB类未找到某方法, 则会调用__call魔术方法调用原生PDO类方法


Connect MySQL Database

<?php
$configs = array(
    'dsn' => array('host' => '127.0.0.1', 'dbname' => 'test', 'port' => 6666),
    'username' => 'test',
    'password' => 'AbcdefRDvgedf',
);

//$mysql = new Asf_Db_Adapter_Mysql($configs);
$mysql = new Asf\Db\Adapter\Mysql($configs);
$mysql->setTable('test1');

Examples

Example #1 先连接DB, 事务操作

<?php
use Asf\Db;

try {
    Db::beginTransaction();
    $data = Db::update(array('status' => 3), array('id' => 123));
    Db::commit();
} catch (PDOException $e) {
    Db::rollBack();
}

Example #2 lastInsertId

<?php
use Asf\Db;

$ret = Db::addByArray(
        array(
            'user' => 'test4',
            'pass' => 'test1',
            'status' => 1
        )
    );

if ($ret) {
    var_dump(Db::lastInsertId()); // 1407
}

Example #3 errorCode errorInfo

<?php
use Asf\Db;

try {
    $ret = Db::addByArray(
        array(
            'user' => 'test4',
            'pass' => 'test1',
            'status' => 1
        )
    );
} catch (Exception $e) {
    var_dump($e->errorcode());
    var_dump($e->errorInfo());
}