我有一个问题与'soapClient',错误日志:
[Wed Mar 26 20:23:15 2014] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined function DB() in /home/optim/DEW/task/Functions.php on line 12
[Wed Mar 26 20:23:15 2014] [error] [client 127.0.0.1] PHP Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Call to undefined function DB() in /home/optim/DEW/task/client.php:6nStack trace:n#0 /home/optim/DEW/task/client.php(6): SoapClient->__call('getClases', Array)n#1 /home/optim/DEW/task/client.php(6): SoapClient->getClases()n#2 {main}n thrown in /home/optim/DEW/task/client.php on line 6
代码函数 getclasses ():
public function getClases() {
$query = "SELECT CLASS, COLOR FROM clases";
$getDB = DB($query);
return $getDB;
}
错误在:
$getDB = DB($query);
我试图包括在调用数据库,它的工作。这是代码:
public function getClases() {
$query = "SELECT CLASS, COLOR FROM clases";
$host = "localhost";
$user = "dwes";
$db = "class";
$pass = "123456";
$odb = new PDO("mysql:host=".$host.";dbname=".$db, $user, $pass);
$odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$resultClase = $odb->query($query);
}
catch (PDOException $p) {
echo "Error ".$p->getMessage()."<br/>";
}
return $resultClase;
}
在使用soap客户端之前,这个应用程序工作得很好。为什么它说"调用未定义的函数DB()"?
问题在哪里?谢谢你的帮助
DB在getClasses()函数的作用域中没有定义。你可以使用PHP的"global"。
。
global $odb;
$odb = new PDO("mysql:host=".$host.";dbname=".$db, $user, $pass);
$odb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
现在,在我的getClasses()函数中,我可以使用全局的"odb"
public function getClases() {
$query = "SELECT CLASS, COLOR FROM classes";
$getDB = $odb($query);
return $getDB;
}