Created
May 6, 2013 18:32
-
-
Save phalcon/5527074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Phalcon\DI, | |
| Phalcon\Events\Manager as EventsManager, | |
| Phalcon\Db\Adapter\Pdo\Sqlite as Connection, | |
| Phalcon\Mvc\Model\Manager as ModelsManager, | |
| Phalcon\Mvc\Model\Metadata\Memory as ModelsMetaData; | |
| $eventsManager = new EventsManager(); | |
| $di = new DI(); | |
| $connection = new Connection(array( | |
| "dbname" => "robots1.db" | |
| )); | |
| $connection->setEventsManager($eventsManager); | |
| $eventsManager->attach('db', | |
| function ($event, $connection) { | |
| switch ($event->getType()) { | |
| case 'beforeQuery': | |
| echo $connection->getSqlStatement(), '<br>'; | |
| break; | |
| } | |
| } | |
| ); | |
| if (!$connection->tableExists('robots')) { | |
| $connection->execute('CREATE TABLE robots (id integer primary key, name varchar(120) not null, type varchar(32) default "mechanical", year int default 2000)'); | |
| $connection->execute('INSERT INTO robots VALUES (1, "hello 1", "x", 1990)'); | |
| $connection->execute('INSERT INTO robots VALUES (2, "hello 2", "y", 2190)'); | |
| } | |
| echo '<p><h3>DEFAULT</h3>'; | |
| $robots = $connection->fetchAll('SELECT * FROM robots'); | |
| var_dump($robots); | |
| echo '</p>'; | |
| echo '<p><h3>FETCH_BOTH</h3>'; | |
| $robots = $connection->fetchAll('SELECT * FROM robots', Phalcon\DB::FETCH_BOTH); | |
| var_dump($robots); | |
| echo '</p>'; | |
| echo '<p><h3>FETCH_ASSOC</h3>'; | |
| $robots = $connection->fetchAll('SELECT * FROM robots', Phalcon\DB::FETCH_ASSOC); | |
| var_dump($robots); | |
| echo '</p>'; | |
| echo '<p><h3>FETCH_NUM</h3>'; | |
| $robots = $connection->fetchAll('SELECT * FROM robots', Phalcon\DB::FETCH_NUM); | |
| var_dump($robots); | |
| echo '</p>'; | |
| echo '<p><h3>FETCH_OBJ</h3>'; | |
| $robots = $connection->fetchAll('SELECT * FROM robots', Phalcon\DB::FETCH_OBJ); | |
| var_dump($robots); | |
| echo '</p>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment