2012-12-25 4 views
0

가능한 중복 :
How can you run a mysqli query with CodeIgniter?PHP에서 STMT 쿼리를 준비

내가 php.But에서 실행하는 것을 시도하고 그것이 나에게 SQL을주고있다 MySQL의 쿼리를했습니다 codeigniter에서 구문 오류가 발생했습니다. 동일한 검색어를 붙여 넣은 후 에서 @uid@rangee을 올바른 값으로 바꿔서 복사하면 제대로 작동합니다.

$this->db->query(" 
      SET @uid = ".mysqli_real_escape_string($conid,$userid)."; 
      SET @rangee = ".mysqli_real_escape_string($conid,$attempt)." * 50; 

      PREPARE STMT FROM 
      ' 
      UPDATE  
       notificationrecievers 
       SET notificationrecievers.status=1 
       WHERE notificationrecievers.status=0 and notificationrecievers.recieverid=? and 

       notificationrecievers.notificationid <= 
       (
        SELECT MAX(notid) FROM 
        (
         SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE 
         nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC 
         LIMIT 50 OFFSET ? 
        )e 
       ) 

       AND 

       notificationrecievers.notificationid >= 
       (
        SELECT min(notid) FROM 
        (
         SELECT n.notid FROM user u,notifications n,notificationrecievers nr WHERE 
         nr.recieverid=? AND u.userid=n.senderid AND nr.notificationid=n.notid ORDER BY n.notid DESC 
         LIMIT 50 OFFSET ? 
        )g 
       );'; 
      EXECUTE STMT USING @uid,@uid,@rangee,@uid,@rangee;"); 

이 왜 나에게 오류를주고있다 : 여기

쿼리입니까?

+1

음과 같이 준비된 명령문의 PHP 래퍼를 사용한다, 어떤 오류 그것은 당신을주고있다? – Amber

답변

1

우선, query() 메서드는 다중 쿼리를 수행하기위한 것이 아닙니다. 다음 코드는 $ userid 변수를 통한 주입을 허용합니다. 이 매뉴얼

0

에 설명 된 것 이진 준비된 문에이 원료 준비된 문에서

더 나은 이동, 그것은 this-> 데시벨이 어떤 종류의 개체 $ 사용자 코드에서 말할 완전히 불가능하다. 이스케이프 처리에 사용되는 mysqli 인 경우 query() 함수는 다중 문을 지원하지 않습니다. 당신은 PHP에서 준비된 문을 사용할 때

또한, 당신이 mysqli::prepare()

+0

'codeigniter'에서 mysqli를 사용하고 있습니다. 필자는 $ this-> db를 사용하여 데이터베이스를 호출하는 태그에 codeigniter를 언급했습니다. – user1256956

관련 문제