2017-11-21 2 views
-4

치명적인 오류가 발생했습니다. stackoverflow 및 다른 포럼에서 해결책을 찾으려고했지만 찾지 못했습니다. 나는이 당신을 도울 수 있습니다 희망치명적인 오류 : 문자열에서 구성원 함수 query()를 호출합니다.

Fatal error: Call to a member function query() on string in /home/......./check.php on line 19

class M_login extends CI_Model{ 
    public function num_of_students($name,$adress){  
     $sql="select * from tbl_admin where name='$name' and address='$address'";  
     $query=$this->db->query($sql);  
     return $query->num_rows(); 
    } 
+0

'$ this-> db'의 내용은 무엇입니까? –

+1

[Little Bobby] (http://bobby-tables.com/)에서 ** [SQL 주입 공격의 위험이 있습니다.] (https://stackoverflow.com/q/60174/) **라고 말합니다. [매개 변수가있는 쿼리] (https://stackoverflow.com/a/4712113/5827005)로 [Prepared Statements] (https://en.wikipedia.org/wiki/Prepared_statement)에 대해 알아보십시오. 매개 변수화되지 않은 쿼리를 사용하는 것보다 쉽고 깨끗하며 안전성을 높이기 위해 [클래스를 작성했습니다] (https://github.com/GrumpyCrouton/GrumpyPDO)라는 'PDO'를 권장합니다. 또한, [이 기사] (https://phpdelusions.net/pdo/mysqli_comparison)는'MySQLi'와'PDO' 중 하나를 선택할 때 도움이 될 수 있습니다 – GrumpyCrouton

+2

** 평범한 텍스트 암호를 저장하지 마십시오! ** PHP의 [built- in function] (http://jayblanchard.net/proper_password_hashing_with_PHP.html) ** ('password_hash()'및'password_verify()')를 사용하여 암호 보안을 처리 할 수 ​​있습니다. 5.5보다 작은 PHP 버전을 사용하고 있다면'password_hash()'[compatibility pack] (https://github.com/ircmaxell/password_compat)을 사용할 수 있습니다. ** 해싱을하기 전에 [암호 제거] (http://stackoverflow.com/q/36628418/1011527) 할 필요가 없습니다. 또는 다른 정리 메커니즘을 사용하십시오. 암호를 변경하면 불필요한 추가 코딩이 발생합니다. – GrumpyCrouton

답변

0
public function num_of_students($name,$adress){  
    $sql="select * from tbl_admin where name='$name' and address='$address'";  
    $query=$this->db->query($sql)->get();  
    return $query->num_rows(); 
} 

... 감사합니다 : 같은

오류가 보인다!

관련 문제