workman里封裝的數(shù)據(jù)庫方法,where 可以直接用in方法嗎。我用了,它報錯。Parse error: syntax error, unexpected 'restart' (T_STRING) in /pi/components/com_work/GatewayWorker/Lib/Gateway.php on line 134
有誰具體用過。具體代碼
public static function getInsertUsers($user,$count){//返回需要增加的用戶列表
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$key = 'maxcont:' .$user;
$c= $redis ->llen($key)-$count;
$rr= $redis -> lRange($key, 0, (int)($c));php /pi/components/com_work/start.php restart
$r= implode(',', $rr);
$db1 = Db::instance('db1');
if( !empty($r) ){
return $db1->select('userid,alias,thumb,latitude,longitude')->from('q_community_users')->where('userid in $r')->query();
}
}
exception 'PDOException' with message 'SQLSTATE: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$r' at line 1' in /pi/components/com_work/GatewayWorker/Lib/DbConnection.php:1751
Parse error: syntax error, unexpected 'restart' (T_STRING)
是PHP語法錯誤啊,自己的問題啊,和workerman數(shù)據(jù)庫類沒毛關(guān)系。
check the manual that corresponds to your MySQL server version for the right syntax to use near '$r'
第二個sql語法錯誤啊,又是你自己的問題啊
where('userid in $r')
改成
where("userid in ($r)")
試下。php變量放到雙引號里才能解析啊,而且你好像還少了個括號。
public static function getInsertUsers($user,$count){//返回需要增加的用戶列表
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$key = 'maxcont:' .$user;
$c= $redis ->llen($key)-$count;
$rr= $redis -> lRange($key, 0, (int)($c));
$r= implode(',', $rr);
$db1 = Db::instance('db1');
if( !empty($r) ){
return $db1->select('userid,alias,thumb,latitude,longitude')->from('q_community_users')->where("userid in( '$r')")->query();//where("userid in ($r)")
}
}
報錯信息exception 'PDOException' with message 'SQLSTATE: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in( '422,421,421,420,419,418,417,416,415')' at line 1' in /pi/components/com_work/GatewayWorker/Lib/DbConnection.php:1751 Stack trace:
終于不報錯了
public static function getInsertUsers($user,$count){//返回需要增加的用戶列表
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$key = 'maxcont:' .$user;
$c= $redis ->llen($key)-$count;
$rr= $redis -> lRange($key, 0, (int)($c));
$db1 = Db::instance('db1');
if( !empty($rr) ){
return $db1->select('userid,alias,thumb,latitude,longitude')->from('q_community_users')->where(" userid in (" . implode(',',$rr) . ")")->query();
}
}