1 function checkStr($username){ 2 //自定义字符串规则 3 } 4 5 function checkLogin($username,$password){ 6 7 $password = md5($password); 8 9 $username = addslashes($username);//转义 10 11 $sql = "select * from {$this->getTableName()} where u_username='{$username}' and u_password='{$password}'"; 12 13 return $this->db_getRow($sql); 14 }
大概分两步,先自定义字符串规则如去除空格特殊符号等等,再使用转义,后面的语句一定要加上单引号。