Simple PDO database connector
filed in Database, Module: v3pdo, PDO on Jul.26, 2010
If you find the Kohana database connector a bit to complex and/or like PHP PDO, why not use that instead?
All this module does is provide a config file, and replace the Models database connector with PDO.
Example code:
<?php defined('SYSPATH') OR die('No direct access allowed.');
class foo extends Model
{
public function __construct()
{
parent::__construct();
}
public function bar()
{
foreach ($this->pdo->query('SELECT id, username FROM users') as $row)
{
echo $row['id'].': '.$row['username'].'<br />';
}
}
}
The major benifits with this module is
- PDO is very well documented.
- PDO is native PHP and is very fast.
Furthermore you can do query building with prepared statements and all other kind of neat stuff, if you want to. Personally I like the simpleness of just using query().
Multiple connections
You can configure multiple database connections.
Example in config (modules/pdo/config/pdo.php) file:
return array
(
'default' => array
(
'driver' => 'mysql',
'hostname' => 'localhost',
'database_name' => 'foo',
'username' => 'user',
'password' => 'pass',
),
'files' => array
(
'driver' => 'sqlite',
'database_name' => '/var/sqlite.db',
),
Access the alternate database driver with:
$pdo_sqlite = new Kohana_pdo('files');
$pdo_sqlite->query('SELECT * FROM users');
July 27th, 2010 on 02:00:11
[...] ICE Online Detainee Locator System searchable database | Private …DesignDivine Project Blog Blog Archive DDv6 Database Table …New Online Database: California: Proposition 8 Contributions (Who …Simple PDO database connector – Kohana modules [...]