2012-03-19 13:24:36 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* Free Query Builder / Database Abstraction Layer
|
|
|
|
*
|
2012-04-20 13:17:39 -04:00
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren
|
2012-03-19 13:24:36 -04:00
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/Query
|
2012-04-20 13:17:39 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-03-19 13:24:36 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Autoloader for loading available database classes
|
|
|
|
*/
|
|
|
|
|
2012-04-19 11:42:50 -04:00
|
|
|
/**
|
|
|
|
* Reference to root path
|
|
|
|
*/
|
2012-04-30 16:06:06 -04:00
|
|
|
define('QBASE_PATH', dirname(__FILE__).'/');
|
2012-04-19 11:42:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path to driver classes
|
|
|
|
*/
|
2012-04-30 16:06:06 -04:00
|
|
|
define('QDRIVER_PATH', QBASE_PATH.'drivers/');
|
2012-03-19 13:24:36 -04:00
|
|
|
|
2012-04-12 14:00:42 -04:00
|
|
|
if ( ! function_exists('do_include'))
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
2012-04-19 11:42:50 -04:00
|
|
|
/**
|
|
|
|
* Bulk directory loading workaround for use
|
|
|
|
* with array_map and glob
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-04-12 14:00:42 -04:00
|
|
|
function do_include($path)
|
|
|
|
{
|
|
|
|
require_once($path);
|
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
}
|
|
|
|
|
2012-05-21 15:18:06 -04:00
|
|
|
/**
|
|
|
|
* Load a Query class
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
*/
|
|
|
|
function query_autoload($class)
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2012-05-21 15:18:06 -04:00
|
|
|
$class = strtolower($class);
|
2012-05-29 14:52:27 -04:00
|
|
|
|
2012-05-21 18:00:18 -04:00
|
|
|
// Load Firebird separately
|
2012-05-29 14:52:27 -04:00
|
|
|
if (function_exists('fbird_connect') && $class === 'firebird')
|
2012-05-21 18:00:18 -04:00
|
|
|
{
|
2012-05-29 14:52:27 -04:00
|
|
|
array_map('do_include', glob(QDRIVER_PATH.'/firebird/*.php'));
|
2012-05-21 18:00:18 -04:00
|
|
|
return;
|
|
|
|
}
|
2012-05-29 14:52:27 -04:00
|
|
|
|
2012-05-21 15:18:06 -04:00
|
|
|
$class_path = QBASE_PATH . "classes/{$class}.php";
|
2012-05-29 14:52:27 -04:00
|
|
|
|
2012-05-21 15:18:06 -04:00
|
|
|
$driver_path = QDRIVER_PATH . "{$class}";
|
2012-03-19 13:24:36 -04:00
|
|
|
|
2012-05-21 15:18:06 -04:00
|
|
|
if (is_file($class_path))
|
2012-03-19 13:24:36 -04:00
|
|
|
{
|
2012-05-21 15:18:06 -04:00
|
|
|
require_once($class_path);
|
|
|
|
}
|
|
|
|
elseif (is_dir($driver_path))
|
|
|
|
{
|
2012-07-03 13:00:17 -04:00
|
|
|
if (in_array($class, PDO::getAvailableDrivers()))
|
2012-05-21 15:18:06 -04:00
|
|
|
{
|
|
|
|
array_map('do_include', glob("{$driver_path}/*.php"));
|
|
|
|
}
|
2012-03-19 13:24:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-21 15:18:06 -04:00
|
|
|
// Set up autoloader
|
|
|
|
spl_autoload_register('query_autoload');
|
|
|
|
|
2012-04-17 16:57:28 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-04-10 14:06:34 -04:00
|
|
|
/**
|
|
|
|
* Filter out db rows into one array
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @param mixed $index
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function db_filter($array, $index)
|
|
|
|
{
|
|
|
|
$new_array = array();
|
|
|
|
|
2012-05-14 12:34:12 -04:00
|
|
|
foreach($array as &$a)
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
|
|
|
$new_array[] = $a[$index];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $new_array;
|
2012-03-19 13:24:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of autoload.php
|