Ich bin von MySQL auf PDO migrieren. Ich schaffe eine Funktion, aber wenn get Fehler Aufruf:PDO Prepare-Anweisung löst einen Fehler
Catchable fatal error: Object of class stdClass could not be converted to string in file * on line **
nicht sicher, wie diese Art der Migration zu behandeln, wenn ich „e.match_id =‚$ row1-> match_id‘“ Sachen haben. Code mit alten mysql:
$query11 = "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')";
$result11 = mysql_query($querye11);
$row11 = mysql_fetch_object($result11);
Funktion mit PDO:
public function getResult11($row)
{
$query = "SELECT COUNT(e.event_id) as numgoals
FROM event e
WHERE (e.match_id = '?->match_id' AND e.team_id = '?->team_a_id' AND e.eventtype IN ('soc_G','soc_PG')) OR
(e.match_id = '?->match_id' AND e.team_id = '?->team_b_id' AND e.eventtype = 'soc_OG')";
$statement = $this->db->prepare($query);
$statement->execute(array($row));
return $statement->fetchObject();
}
Wie "e.match_id = '$ row1-> match_id'" konvertieren "$ row1" mit Funktionsparameter zu ändern? Ich habe dieses "e.match_id = '? -> match_id'" verwendet, bin mir aber nicht sicher, ob es richtig ist.
uns Zeigen Sie, was in '$ row ist ' – RiggsFolly
Das '? -> match_id 'ist NICHT die richtige Syntax. Wünschen Sie einen benannten Parameter, d. H. ': Match_id' oder Positionsparameter, d. H.' ' – RiggsFolly
' $ row' ist eine andere Abfrage. Nicht sicher, ich werde das verwenden, das passt am besten zu meinem Fall. – Sagi