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

47 lines
1.0 KiB
PHP
Raw Normal View History

2010-08-03 12:28:07 +02:00
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
<h1>Result Set Data Types | dibi</h1>
2010-08-03 12:28:07 +02:00
2008-07-17 03:51:29 +00:00
<?php
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install dependencies using `composer install --dev`');
}
Tracy\Debugger::enable();
2008-07-17 03:51:29 +00:00
date_default_timezone_set('Europe/Prague');
2008-07-17 03:51:29 +00:00
dibi::connect(array(
2015-06-19 03:11:36 +02:00
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
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)
2012-01-18 21:08:34 +01:00
->setType('added', Dibi::DATETIME)
->setFormat(dibi::DATETIME, 'Y-m-d H:i:s');
2008-07-17 03:51:29 +00:00
2015-06-19 03:11:36 +02:00
Tracy\Dumper::dump($res->fetch());
2010-08-03 11:48:51 +02:00
// outputs:
2013-06-23 01:57:48 +02:00
// DibiRow(3) {
// customer_id => 1
// name => "Dave Lister" (11)
// added => "2007-03-11 17:20:03" (19)
2010-08-03 11:48:51 +02:00
// using auto-detection (works well with MySQL or other strictly typed databases)
$res = dibi::query('SELECT * FROM [customers]');
2015-06-19 03:11:36 +02:00
Tracy\Dumper::dump($res->fetch());
2008-10-28 02:06:55 +00:00
// outputs:
2013-06-23 01:57:48 +02:00
// DibiRow(3) {
// customer_id => 1
// name => "Dave Lister" (11)
// added => "2007-03-11 17:20:03" (19)