致命错误:在非对象上调用成员函数execute()

时间:2014-01-08 13:01:19

标签: php

我遇到了execute()的问题:致命错误:在非对象上调用成员函数execute() 我似乎已经正确使用它,我在StackOverflow上查找了其他问题,我认为这是正确的。

  $db = dbConnect();
  $query = "SELECT * FROM 'users' WHERE 'username' = '".$username."'";
  $stmt = $db->prepare($query);
  $stmt->execute();

其中dbConnect()是函数:

  function dbConnect() {
      $db = mysqli_connect("localhost", "root", "example", "dbexample")
          or die("Errore nella connessione al db: " . mysqli_connect_error());
      return $db;
  }

由于

2 个答案:

答案 0 :(得分:0)

请使用此:

$query = "SELECT * FROM `users` WHERE 'username' = '".$username."'";

而不是:

$query = "SELECT * FROM 'users' WHERE 'username' = '".$username."'";

答案 1 :(得分:0)

试试这个

<?php
$db = mysqli_connect("localhost", "root", "example", "dbexample")
          or die("Errore nella connessione al db: " . mysqli_connect_error());
      $stmt = $db->prepare("SELECT * FROM users where username =".$username);
      $stmt->execute();
?>