function connect(){
$db = new mysqli(localhost, bludevel_PMI, password1, bludevel_PMIForm);
if ($db->connect_errno) {
echo json_encode(array($mysqli->connect_error));
return false;
exit();
}}
function disConnect(){
mysqli_close($db);
}
function downloadData(){
if ($_POST['cmd'] == "downloadData"){
$result = $db->query("SELECT * FROM Jobs");//error on this line
if($result){
while ($row = $result->fetch_array()){
$jobs[$row['PMINumber']] = $row['Address'];
}
//$result->close();
//$db->next_result();
}
$result = $db->query("SELECT * FROM Installers ORDER BY `Order` ASC");
if($result){
while ($row = $result->fetch_array()){
$installers[] = $row['Names'];
}
//$result->close();
//$db->next_result();
}
echo json_encode(array($jobs, $installers));
return true;
}}
我得到错误PHP Fatal error: Call to a member function query() on a non-object
当我运行这个脚本。 $ db确实是一个对象,我已经在其他 函数中成功使用它,所以问题必须在函数本身内。我是新来的PHP,所以任何 帮助非常感谢。呼叫成员函数在非对象
变量作用域。它在连接函数中定义,但不会传递到任何外部变量。 – mario 2013-02-23 23:44:46
[PHP:变量不能在函数内部工作吗?]可能的重复(http://stackoverflow.com/questions/3041171/php-variable-not-working-inside-of-function) – mario 2013-02-23 23:46:16
“断开”拼写为“断开连接“,而不是”disConnect“。这不是两个字。 – meagar 2013-02-23 23:47:49