php-pdo-mysql-helper-class
php-pdo-mysql-helper-class copied to clipboard
New functions made
Hi, great job...
I have created new specific functions for my job. If you think be useful, merge it:
public function getValue($table, $col, $value, $col_returned)
{
$sqld = "SELECT `$col_returned` FROM `$table` WHERE $col='".$value."'";
$q = $this->pdo->prepare($sqld);
$q->execute();
$f = $q->fetch();
$result = $f[$coluna_retornada];
return $result;
}
public function getMaxValue($table, $col, $value, $col_returned)
{
$sqld = "SELECT MAX($col_returned) as total FROM `$table` WHERE $col ='".$value."'";
$q = $this->pdo->prepare($sqld);
$q->execute();
$f = $q->fetch();
$result = $f["total"];
return $result;
}
public function getTotal($table, $col, $value)
{
$sqld = "SELECT COUNT(*) as total FROM `$table` WHERE $col='".$value."'";
$q = $this->pdo->prepare($sqld);
$q->execute();
$f = $q->fetch();
$result = $f["total"];
return $result;
}
public function getTotalWhere($table, $where)
{
$data = array_values( $where );
$cols=array_keys($where);
foreach ($cols as $key) {
$keys=$key."=?";
$mark[]=$keys;
}
$jum=count($where);
if ($jum>1) {
$im=implode(' and ', $mark);
$sqlget = "SELECT COUNT(*) as total from $table WHERE $im";
$sel = $this->pdo->prepare($sqlget);
} else {
$im=implode('', $mark);
$sqlget = "SELECT COUNT(*) as total from $table WHERE $im";
$sel = $this->pdo->prepare($sqlget);
}
$sel->execute( $data );
$f = $sel->fetch();
$result = $f["total"];
return $result;
}
i've invited you, you can merge it yourself now