Thanks for all the help folks,
PHP-light-PDO-Class
ok well I found this...
https://github.com/poplax/PHP-light-PDO-Class
But it does not seem to recognize the port - I put the port as 8889 but keeps
saying can't connect port 3306
Warning: PDO::__construct() [pdo.--construct]: [2002] Connection refused
(trying to connect via tcp://127.0.0.1:3306) in
/Users/revdave/Sites/php-fool/pdo3/PHP-light-PDO-Class-master/class.lpdo.php on
line 33
Connection failed: SQLSTATE[HY000] [2002] Connection refused
BTW: I tried to add the port a few places but it didn't work..
How do we fix this?
-- config.php
=== class.lpdo.php
options = $options;
$dsn = $this->createdsn($options);
$attrs = empty($options['charset']) ?
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES " . $this->charset) :
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES " . $options['charset']);
try
{
parent::__construct($dsn, $options['username'],
$options['password'], $attrs);
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
}
/**
*
* @Function : createdsn;
* @Param $ : $options Array;
* @Return String ;
*/
private function createdsn($options)
{
return $options['dbtype'] . ':host=' . $options['host'] .
';dbname=' . $options['dbname'];
}
/**
*
* @Function : get_fields;
* @Param $ : $data Array;
* @Return String ;
*/
private function get_fields($data)
{
$fields = array();
if (is_int(key($data)))
{
$fields = implode(',', $data);
}
else if (!empty($data))
{
$fields = implode(',', array_keys($data));
}
else
{
$fields = '*';
}
return $fields;
}
/**
*
* @Function : get_condition;
* @Param $ : $condition Array, $oper String, $logc String;
* @Return String ;
*/
private function get_condition($condition, $oper = '=', $logc = 'AND')
{
$cdts = '';
if (empty($condition))
{
return $cdts = '';
}
else if (is_array($condition))
{
$_cdta = array();
foreach($condition as $k => $v)
{
if (!is_array($v))
{
if (strtolower($oper) == 'like')
{
$v = '\'%' . $v . '%\'';
}
else if (is_string($v))
{
$v = '\'' . $v . '\'';
}
$_cdta[] = ' ' . $k . ' ' . $oper . ' '
. $v . ' ' ;
}
else if (is_array($v))
{
$_cdta[] = $this->split_condition($k,
$v);
}
}
$cdts .= implode($logc, $_cdta);
}
return $cdts;
}
/**
*
* @Function : split_condition;
* @Param $ : $field String, $cdt Array;
* @Return String ;
*/
private function split_condition($field, $cdt)
{
$cdts = array();
$oper = empty($cdt[1]) ? '=' : $cdt[1];
$logc = empty($cdt[2]) ? 'AND' : $cdt[2];
if (!is_array($cdt[0]))
{
$cdt[0] = is_string($cdt[0]) ? "'$cdt[0]'" : $cdt[0];
}
else if (is_array($cdt[0]) || strtoupper(trim($cdt[1])) == 'IN')
{
$cdt[0] = '(' . implode(',', $cdt[0]) . ')';
}
$cdta[] = " $field $oper {$cdt[0]} ";
if (!empty($cdt[3]))
{
$cdta[] = $this->get_condition($cdt[3]);
}
$cdts = ' ( ' . implode($logc, $cdta) . ' ) ';
return $cdts;
}
/**
*
* @Function : get_fields_datas;
* @Param $ : $data Array;
* @Return Array ;
*/
private function get_fields_datas($data)