2012-10-31 16:21:15 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* Free Query Builder / Database Abstraction Layer
|
|
|
|
*
|
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren
|
2014-01-02 12:36:50 -05:00
|
|
|
* @copyright Copyright (c) 2012 - 2014
|
2012-10-31 16:21:15 -04:00
|
|
|
* @link https://github.com/aviat4ion/Query
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2014-03-31 12:47:07 -04:00
|
|
|
* Global functions that don't really fit anywhere else
|
2012-10-31 16:21:15 -04:00
|
|
|
*/
|
2012-11-08 14:28:49 -05:00
|
|
|
|
2012-10-31 16:21:15 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('do_include'))
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bulk directory loading workaround for use
|
|
|
|
* with array_map and glob
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function do_include($path)
|
|
|
|
{
|
|
|
|
require_once($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('mb_trim'))
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Multibyte-safe trim function
|
|
|
|
*
|
2014-02-07 16:53:01 -05:00
|
|
|
* @param string $string
|
2012-10-31 16:21:15 -04:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function mb_trim($string)
|
|
|
|
{
|
|
|
|
return preg_replace("/(^\s+)|(\s+$)/us", "", $string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter out db rows into one array
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @param mixed $index
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function db_filter($array, $index)
|
|
|
|
{
|
|
|
|
$new_array = array();
|
|
|
|
|
|
|
|
foreach($array as $a)
|
|
|
|
{
|
|
|
|
$new_array[] = $a[$index];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $new_array;
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:02:31 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-11-08 14:28:49 -05:00
|
|
|
/**
|
|
|
|
* Connection function
|
|
|
|
*
|
|
|
|
* @param mixed $params
|
|
|
|
* @return Query_Builder
|
|
|
|
*/
|
2014-02-14 22:08:19 -05:00
|
|
|
function Query($params = '')
|
2012-11-08 14:28:49 -05:00
|
|
|
{
|
2014-03-31 12:47:07 -04:00
|
|
|
$cmanager = Connection_Manager::get_instance();
|
2014-02-25 13:55:19 -05:00
|
|
|
|
2014-02-07 16:53:01 -05:00
|
|
|
// If you are getting a previously created connection
|
|
|
|
if (is_scalar($params))
|
2012-11-08 20:02:31 -05:00
|
|
|
{
|
2014-03-31 12:47:07 -04:00
|
|
|
return $cmanager->get_connection($params);
|
2012-11-08 20:02:31 -05:00
|
|
|
}
|
2012-11-08 14:28:49 -05:00
|
|
|
|
2014-03-31 12:47:07 -04:00
|
|
|
// Otherwise, return a new connection
|
|
|
|
return $cmanager->connect($params);
|
2012-11-08 14:28:49 -05:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:53:01 -05:00
|
|
|
// End of common.php
|