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->setTableName('test1');

Examples

Example #1 事务操作

<?php
Asf_Db::beginTransaction();
$data = Asf_Db::update(array('status' => 3), array('id' => 123));
Asf_Db::commit();

Example #2 lastInsertId

<?php
$ret = Asf_Db::addByArray(
        array(
            'user' => 'test4',
            'pass' => 'test1',
            'status' => 1
        )
    );

if ($ret) {
    var_dump(Asf_Db::lastInsertId());
}

// string(4) "1407"

Example #3 errorCode errorInfo

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