public function selectRecord($table, $records=null, $where=NULL, $order=NULL, $limit=NULL)
{
#If table is empty, it will return an error message
if(!empty($table))
{
$whe = '';
$lim = '';
$ord = '';
#if $records are empty, will select all columns
if(empty($records))
{
$cols = '*';
}
else
{
$cols = implode(',',$records);
}
#if there is a $where
if(!empty($where))
{
#Where statement construction
foreach($where as $column => $value)
{
#if the value is numeric
if(is_numeric($value))
{
$whe = "$whe AND $column = :$column ";
}
#if the value is a decimal
else if(is_float($value))
{
$whe = "$whe AND $column = :$column ";
}
#if the value is a string
else if(is_string($value))
{
$whe = "$whe AND $column like :$column ";
}
#if the value is empty
else if(empty($value))
{
$whe = "$whe AND $column is null ";
}
}
}
#if there is an $order
if(!empty($order))
{
$ord = "ORDER BY ";
foreach($order as $column => $or)
{
#for each value in the array it will construct an order statement
$ord = $ord . " $column $or,";
}
#remove the last comma
$ord = substr($ord, 0, -1);
}
#if there is a limit
if(!empty($limit))
{
#construction of the limit statement
$lim = 'LIMIT ' . $limit[0] . $limit[1];
}
$con = $this->conectionDatabase();
$query = $con->prepare("SELECT $cols FROM $table WHERE 1 $whe $ord $lim");
if(!empty($where))
{
foreach($where as $column => $value)
{
#Bind values depending if is numeric, float or string
if(is_numeric($value))
{
$query->bindValue(":$column",$value, PDO::PARAM_INT);
}
if(is_float($value))
{
$query->bindValue(":$column",$value, PDO::PARAM_STR);
}
if(is_string($value))
{
$query->bindValue(":$column",$value, PDO::PARAM_STR);
}
}
}
#execute query
$query->execute();
$rowcount = $query->rowCount();
$data = $query->fetchAll(PDO::FETCH_OBJ);
#set $data, $rowcount values
$this->setData($data, $rowcount, NULL);
return $this->getData();
}
else
{
$this->setError(2);
}
}
Necesito modificar el parametro del WHERE para que reciba condiciones de <, >, =>, etc y que pueda recibir mas de una condición WHERE. Alguien me ayuda por favor.