<?php class 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 } }
phalcon mysql 日志 添加
最新推荐文章于 2021-02-28 20:08:55 发布