workman里封装的数据库方法,where 可以直接用in方法吗

xamarin

workman里封装的数据库方法,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();

        } 
    }
3646 5 0
5个回答

xamarin

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

  • 暂无评论
damao

Parse error: syntax error, unexpected 'restart' (T_STRING)

是PHP语法错误啊,自己的问题啊,和workerman数据库类没毛关系。

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变量放到双引号里才能解析啊,而且你好像还少了个括号。

  • 暂无评论
xamarin

上面的说法很中肯,也很真实,我也改过来了。尝试in的各种写法,现在还是报错

  • 暂无评论
xamarin
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:

  • 暂无评论
xamarin

终于不报错了

 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();              
        } 
    }
  • 暂无评论
年代过于久远,无法发表回答
×
🔝