我收到以下错误:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error
in your SQL syntax;
但是,我无法解决。行号说它是 15 这是
$res->execute(array_values($params));
你能发现问题吗?
function fetchBgnew(array $conditions){
$db = Core::getInstance();
$sql = "SELECT p.id, p.bg, p.bg_desc, p.bg_id, p.user_id, p.panel_id, p.domainurl,
p.type, p.price
FROM ".USERS_BG." as p
left join ".USERS." as u on p.user_id=u.id WHERE u.status !=0 and 1 and";
$params = array();
foreach ($conditions as $column => $value) {
if (preg_match('/^[a-z]+$/', $column)) {
$sql .= "$column = ?";
$params[] = $value;
$sql .= "group by p.id desc, LIMIT 0,25";
}
}
$res = $db->dbh->prepare($sql);
$res->execute(array_values($params));
$res->fetchAll(PDO::FETCH_ASSOC);
$sql="SELECT p.id FROM ".USERS_BG." as p
left join ".USERS." as u on p.user_id=u.id WHERE u.status !=0 and";
$params = array();
foreach ($conditions as $column => $value) {
if (preg_match('/^[a-z]+$/', $column)) {
$sql .= "$column = ? group by p.id desc LIMIT 0,25";
$params[] = $value;
}
}
$cnt = $db->dbh->prepare($sql);
$cnt->execute(array_values($params));
$cnt->rowCount();
return $result = array("data"=>$res, "count"=>$cnt);
}
function fetchUser(array $conditions){
$db = Core::getInstance();
$sql = "SELECT id FROM ruj_users_jel WHERE";
$params = array();
foreach ($conditions as $column => $value) {
if (preg_match('/^[a-z]+$/', $column)) {
$sql .= "$column = ?";
$params[] = $value;
}
}
$res = $db->dbh->prepare($sql);
$res->execute(array_values($params));
$numrows = $res->rowCount();
return $numrows;
}
$bgdataarr = fetchBgnew(array("p.status"=>'1'));
$bgdata = $bgdataarr['data'];
$page_title = "Home";
foreach($bgdata as $brag){
print_r($bgdata[$i]['countjellys']=fetchUser(array('brag_id'=>$bg['id'])));
}