Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php PDO不获取任何结果_Php_Mysql_Pdo - Fatal编程技术网

Php PDO不获取任何结果

Php PDO不获取任何结果,php,mysql,pdo,Php,Mysql,Pdo,我在index.php文件中直接使用PDO查询,现在我想创建一个单独的文件,在其中存储函数。我创建了一个,但当我调用时,函数只返回“0”。旧版本作品: $abfrage11 = "SELECT COUNT(e.event_id) as numgoals FROM event e WHERE (e.match_id = '$row1->match_id' AND e.team_id = '$row1->team_a_id' AND e.eventtype IN ('soc_G','s

我在index.php文件中直接使用PDO查询,现在我想创建一个单独的文件,在其中存储函数。我创建了一个,但当我调用时,函数只返回“0”。旧版本作品:

$abfrage11 = "SELECT COUNT(e.event_id) as numgoals
FROM event e 
WHERE (e.match_id = '$row1->match_id' AND e.team_id = '$row1->team_a_id' AND e.eventtype IN ('soc_G','soc_PG') ) OR
      (e.match_id = '$row1->match_id' AND e.team_id = '$row1->team_b_id' AND e.eventtype = 'soc_OG' )";
$ergebnis11 = $dbh->query($abfrage11);
$row11 = $ergebnis11->fetch(PDO::FETCH_OBJ);
但在新版本中,不是:

单独的文件“storage.php”:

调用index.php:

require_once("dblogin.php");
require_once("Storage.php");

$dbFactory = new RepositoriesFactory();
$dbh = $dbFactory->getDataBaseInstance('admgsa_gsa');
$storage_access = new StorageAccess($dbh);

$row11 = $storage_access->getAbfrage11();
echo "<span class='live-monitor-8' style=\"$goalscbgcolor\">$row11->numgoals</span>";
require_once(“dblogin.php”);
需要_一次(“Storage.php”);
$dbFactory=new RepositoriesFactory();
$dbh=$dbFactory->getDataBaseInstance('admgsa_gsa');
$storage\u access=新的StorageAccess($dbh);
$row11=$storage\u access->getAbfrage11();
回显“$row11->numgoals”;

试图寻找解决方案,但什么也找不到。提前感谢您的帮助。

了解问题所在。我没有指定输入参数:

public function getAbfrage11($row1)
    {
        $query = "SELECT COUNT(e.event_id) as numgoals
                    FROM event e 
                    WHERE (e.match_id = :mId AND e.team_id = :tmA AND e.eventtype IN ('soc_G','soc_PG') ) OR
                          (e.match_id = :mId2 AND e.team_id = :tmB AND e.eventtype = 'soc_OG' )";
        $statement = $this->db->prepare($query);
        $statement->execute([
            ':mId' => $row1->match_id,
            ':mId2' => $row1->match_id,
            ':tmA' => $row1->team_a_id,
            ':tmB' => $row1->team_b_id,
        ]);
        return $statement->fetchObject();
    }

这解决了我的问题。

不应该
':mId'=>$row1->team_a_id
应该
':mId'=>$row1->match_id
?如果我没记错,你不能重复使用同一个占位符。@Siguza是的,输入错误,但仍然不会返回任何结果。这是我以前的评论。从文档
中,您不能在准备好的语句中多次使用相同名称的命名参数标记,除非启用了仿真模式。
使用了
':mId'=>$row1->match_id':mId2'=>$row1->match_id,
,并在查询中进行了更改,但没有帮助。
public function getAbfrage11($row1)
    {
        $query = "SELECT COUNT(e.event_id) as numgoals
                    FROM event e 
                    WHERE (e.match_id = :mId AND e.team_id = :tmA AND e.eventtype IN ('soc_G','soc_PG') ) OR
                          (e.match_id = :mId2 AND e.team_id = :tmB AND e.eventtype = 'soc_OG' )";
        $statement = $this->db->prepare($query);
        $statement->execute([
            ':mId' => $row1->match_id,
            ':mId2' => $row1->match_id,
            ':tmA' => $row1->team_a_id,
            ':tmB' => $row1->team_b_id,
        ]);
        return $statement->fetchObject();
    }