在调试php的时候弹出报错
Call to undefined method Database::prepare()
Call to undefined method PdoMySQL::prepare()
解决方法:
参考链接:
https://stackoverflow.com/questions/3716798/call-to-undefined-method-databaseprepare
https://stackoverflow.com/questions/23371118/call-to-undefined-method-pdoexecute#
There is no method prepare in your Database class. That belongs to the PDO object that you are storing as $link.
What you are probably looking for is
Database :: $link->prepare(…)
部分代码段:
public static function query($sql=''){ $link=self::$link; if(!$link) return false; //判断之前是否有结果集,如果有的话,释放结果集 if(!empty(self::$PDOStatement))self::free(); self::$queryStr=$sql; self::$PDOStatement=$link->prepare(self::$queryStr); $res=self::$PDOStatement->execute(); self::haveErrorThrowException(); return $res; }
<?php //error_reporting(0); require_once '../model/PdoMySQL.class.php'; require_once '../model/config.php'; $username=$_GET["username"]; $pdo=new PdoMySQL(); $sql5="select username from admin"; $stmt5=$pdo::$link->prepare($sql5); $stmt5->execute(); while($row5=$stmt5->fetch()){ $usernames[]=$row5['username']; } if(in_array($username,$usernames)){ $response="该账号已注册可"."<a href='../view/login.php'>直接登录</a>"; } echo $response; ?>