我在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”:
class StorageAccess
{
/** @var PDO */
public $db;
/**
* @param $db
*/
public function __construct($db)
{
$this->db = $db;
}
public function getAbfrage11()
{
$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();
}
}
调用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>";
试图搜索解决方案,但找不到任何东西。提前感谢您的帮助。
答案 0 :(得分:-1)
得到了什么问题。我没有指定输入参数:
var sales=db.Customers
.GroupBy(c=>c.SomeColumn)
.Select(g=>new
{
Count1=g.Count(someCondition),
Count2=g.Count(otherCondition)
})
.Select(c=> new MyModel
{
count1=c.Count1,
count2=c.Count2,
finalCount=c.Count1-c.Count2
});
这解决了我的问题。