edoceo

Radix PHP Bootstrap


<?php
/**
	@brief Using the radix_db_sql Database Component
	
*/

require_once('Radix/db/sql.php');

radix_db_sql::init('odbc:Driver={SQL Native Client}; Server=XXXX\SQLEXPRESS; Database=XXXX; Uid=XXXX; Pwd=XXXX;');

// Connecting to PostgreSQL
radix_db_sql::init('pgsql:host=localhost;dbname=foo',$username,$password);

// Connecting to Sqlite
radix_db_sql::init('sqlite:' . APP_ROOT . '/var/sqlite.sdb');

radix_db_sql::init('sqlite::memory:');

// Basic Queries
radix_db_sql::query('CREATE TABLE network (id,name,stub)');

// Get a PDO Query Result Object
$sql = 'SELECT * FROM network';
$res = radix_db_sql::fetch($sql);

// Get a Single Value
$sql = 'SELECT id FROM network LIMIT 1';
$res = radix_db_sql::fetch_one($sql);

// Get a Single Row Array
$sql = 'SELECT * FROM network LIMIT 1';
$res = radix_db_sql::fetch_row($sql);

// Get Result as Array of Records
$sql = 'SELECT * FROM network LIMIT 1';
$res = radix_db_sql::fetch_all($sql);

// query and fetch* take second argument of parameters
$sql = 'SELECT * FROM network WHERE name = ? OR stub = ?';
$arg = array('foo','bar');
$res = radix_db_sql::fetch_all($sql,$arg);

// Named Parameters?
$sql = 'SELECT * FROM network WHERE name = :name OR stub = :stub';
$arg = array(
    'name' => 'foo',
    'stub' => 'bar',
);
$res = radix_db_sql::fetch_all($sql,$arg);

// Insert an Object:
$rec = array(
    'name' => 'Foo Network',
    'stub' => 'foo-net',
);
radix_db_sql::insert('network',$rec);

// Update an Object

// Destory Connection
radix_db_sql::shut();

Loading Comments from Disqus...