无属性,由自动完成输入文本php jquery生成
我不明白为什么查询不起作用,如果我尝试使用localhost就可以了,但是使用“mysql”,我尝试在我的网站中使用PDO,但没有给出结果。我试着查看错误日志,我得到一个这样的错误无属性,由自动完成输入文本php jquery生成,php,jquery,mysql,pdo,Php,Jquery,Mysql,Pdo,我不明白为什么查询不起作用,如果我尝试使用localhost就可以了,但是使用“mysql”,我尝试在我的网站中使用PDO,但没有给出结果。我试着查看错误日志,我得到一个这样的错误 PHP Fatal error: Call to a member function fetch() on a non-object in fungsi/f_record.php on line 9 这是我的消息来源 f_record.php <?php include "../config/c_confi
PHP Fatal error: Call to a member function fetch() on a non-object in fungsi/f_record.php on line 9
这是我的消息来源
f_record.php
<?php
include "../config/c_config.php";
$db = dbConn::getConnection();
$uq = strtolower($_GET["term"]);
$return = array();
$sqlac= "SELECT * FROM str_user WHERE name LIKE '$uq'";
$resac = $db->query($sqlac);
while($resac = $sqlac->fetch(PDO::FETCH_ASSOC)){
array_push($return,array('label'=>$resac['name'],'value'=>$resac['name']));
}
echo(json_encode($return));
?>
仔细阅读错误消息。
对非对象调用成员函数fetch()
在代码中有一个对fetch()
的调用。它是$sqlac->fetch(PDO::fetch\u ASSOC)
$sqlac
是一个字符串。不能对字符串
调用获取
,因为它不是对象
这在。首先正确创建db句柄,我不确定“$db”是如何在代码中创建的,因为您没有提到dbconn::getconnection()的代码。我已将其替换为$dbh
<?php
include "../config/c_config.php";
$db = dbConn::getConnection();
*$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);*
$uq = strtolower($_GET["term"]);
$return = array();
$sqlac = $dbh->prepare("SELECT * FROM str_user WHERE name LIKE '$uq'");
$sqlac->execute();
while($resac = $sqlac->fetch(PDO::FETCH_ASSOC)){
array_push($return,array('label'=>$resac['name'],'value'=>$resac['name']));
}
echo(json_encode($return));
?>
发布你的f_autocomplete_cust.php
服务器上的php版本支持PDO吗?@SO user:sory,我编辑错了written@jQuery:是,支持..可能的副本
<?php
include "../config/c_config.php";
$db = dbConn::getConnection();
*$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);*
$uq = strtolower($_GET["term"]);
$return = array();
$sqlac = $dbh->prepare("SELECT * FROM str_user WHERE name LIKE '$uq'");
$sqlac->execute();
while($resac = $sqlac->fetch(PDO::FETCH_ASSOC)){
array_push($return,array('label'=>$resac['name'],'value'=>$resac['name']));
}
echo(json_encode($return));
?>