如果Asf框架封装的DB类未找到某方法, 则会调用__call魔术方法调用原生PDO类方法
<?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');
<?php use Asf\Db; try { Db::beginTransaction(); $data = Db::update(array('status' => 3), array('id' => 123)); Db::commit(); } catch (PDOException $e) { Db::rollBack(); }
<?php use Asf\Db; $ret = Db::addByArray( array( 'user' => 'test4', 'pass' => 'test1', 'status' => 1 ) ); if ($ret) { var_dump(Db::lastInsertId()); // 1407 }
<?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()); }