1
0
mirror of https://github.com/dg/dibi.git synced 2025-01-17 22:28:50 +01:00
php-dibi/examples/result-set-data-types.php

45 lines
978 B
PHP
Raw Normal View History

2010-08-03 12:28:07 +02:00
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
2010-08-03 11:48:51 +02:00
<h1>Result Set Data Types | dibi</h1>
2010-08-03 12:28:07 +02:00
2008-07-17 03:51:29 +00:00
<?php
2011-07-01 08:06:36 +02:00
require_once 'Nette/Debugger.php';
2008-07-17 03:51:29 +00:00
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
2008-07-17 03:51:29 +00:00
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'data/sample.sdb',
2008-07-17 03:51:29 +00:00
));
2010-08-03 11:48:51 +02:00
// using manual hints
2008-07-17 03:51:29 +00:00
$res = dibi::query('SELECT * FROM [customers]');
2010-08-03 11:48:51 +02:00
$res->setType('customer_id', Dibi::INTEGER)
->setType('added', Dibi::DATETIME);
2008-07-17 03:51:29 +00:00
2011-07-01 08:06:36 +02:00
Debugger::dump( $res->fetch() );
2010-08-03 11:48:51 +02:00
// outputs:
// object(DibiRow)#3 (3) {
// customer_id => int(1)
// name => string(11) "Dave Lister"
// added => object(DateTime53) {}
// }
// using auto-detection (works well with MySQL or other strictly typed databases)
$res = dibi::query('SELECT * FROM [customers]');
2011-07-01 08:06:36 +02:00
Debugger::dump( $res->fetch() );
2008-10-28 02:06:55 +00:00
// outputs:
// object(DibiRow)#3 (3) {
// customer_id => int(1)
// name => string(11) "Dave Lister"
// added => string(15) "17:20 11.3.2007"
// }