phalcon mysql 日志 添加

来源:互联网 发布:买网络教育本科多少钱 编辑:程序博客网 时间:2024/05/14 20:41
<?phpclass Group extends \Phalcon\Mvc\Model{}$di = new \Phalcon\DI\FactoryDefault();$di->set('db',    function()    {        $config = array(            'host' => '127.0.0.1',            'username' => 'root',            'password' => '',            'dbname' => 'test'        );        $em = new \Phalcon\Events\Manager();        $em->attach('db',            function($event, $connection)            {                if ($event->getType() == 'beforeQuery') {                    echo $connection->getSQLStatement(), "\n";                }            }        );        $db = new \Phalcon\Db\Adapter\Pdo\Mysql($config);        $db->setEventsManager($em);        return $db;    });$arrayData = array(    array(        'id'    => 1,        'parent_ref' => null,        'name' => 'yeah'    ),    array(        'id'    => 2,        'parent_ref' => 1,        'name' => 'plop'    ),);foreach ($arrayData as $hash) {    $objGroup = new Group();    $objGroup->id = $hash['id'];    $objGroup->name = $hash['name'];    $objGroup->parent_ref = $hash['parent_ref'];    if (!$objGroup->create()) {        var_dump($objGroup->getMessages());    }

}

SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='group'DESCRIBE `group`SELECT COUNT(*) "rowcount" FROM `group` WHERE `id` = ?array(1) {  [0]=>  object(Phalcon\Mvc\Model\Message)#35 (4) {    ["_type":protected]=>    string(20) "InvalidUpdateAttempt"    ["_message":protected]=>    string(50) "Record cannot be updated because it does not exist"    ["_field":protected]=>    NULL    ["_model":protected]=>    NULL  }}SELECT COUNT(*) "rowcount" FROM `group` WHERE `id` = ?array(1) {  [0]=>  object(Phalcon\Mvc\Model\Message)#37 (4) {    ["_type":protected]=>    string(20) "InvalidUpdateAttempt"    ["_message":protected]=>    string(50) "Record cannot be updated because it does not exist"    ["_field":protected]=>    NULL    ["_model":protected]=>    NULL  }}

0 0
原创粉丝点击