简体   繁体   English

讯息不会回显

[英]Message won't echo

So I have in my DB.php 所以我在我的DB.php中

 public function query($sql, $params = array()){
    $this->_error = false;
    if($this->_query = $this->_pdo->prepare($sql)){
        echo "Success";
    }
}

And in my index.php I have this DB::getInstance()->query("SELECT username FROM users") . 在我的index.php中,我有这个DB::getInstance()->query("SELECT username FROM users") Why doesn't it echo Success ? 为什么它不呼应Success

Try using the double equals... == 尝试使用双等于... ==

Your code now is an assignment in the if statement with one equals. 现在,您的代码是if语句中的一个等于1的赋值。

The code in question now is: if($this->_query = $this->_pdo->prepare($sql)){ 现在有问题的代码是: if($this->_query = $this->_pdo->prepare($sql)){

Try changing this line of code to if($this->_query == $this->_pdo->prepare($sql)){ 尝试将这行代码更改为if($this->_query == $this->_pdo->prepare($sql)){

I hope this helps. 我希望这有帮助。 I do not use the object-oriented style of PHP for the most part, but have used the procedural coding style of PHP quiet a bit. 我大部分时间都没有使用PHP的面向对象风格,而是安静地使用了PHP的过程编码风格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM