如何在PHP中创建通用方法来确定mysql中的行数? 有人请帮忙吗?谢谢。
public function countRow($table, $array)
{
$bef = implode(', ', array_keys($array));
$aft = implode(', ', array_fill(0, sizeof($array), '=?'));
$sql = 'SELECT '.$bef.' FROM '.$table.' WHERE '.$aft.' LIMIT 1';
$stmt = $pdo->prepare($sql);
$stmt->execute(array_values($array));
return $stmt->rowCount();
}
$array = array('name' => $_POST['name'],
'pass' => secure($_POST['pass']),
'status' => 0);
$array = array('single' => $_POST['one']);
$this->countRow('tablename', $array);