Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: de.comp.lang.php Subject: Re: Problem mit PDO Date: Sat, 14 Nov 2015 21:32:05 +0100 Lines: 61 Message-ID: <56479A45.3090901@arnowelzel.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net Ej9VETUMeWbYI5iInv7+xQdgIco0y+LfSMG0g3rSCqOVWgbLUm Cancel-Lock: sha1:UWfCDuuc9vDc2RFPACw68zu9xog= In-Reply-To: Xref: csiph.com de.comp.lang.php:3544 Peter Müller schrieb am 2015-11-14 um 20:54: > Hallo, > > ich arbeite mich gerade mit PDO ein und komme an einem Punkt nicht > weiter, ich hoffe ihr könnt mir helfen. Es geht um die Umsetzung dieser > SQL-Abfrage: > mysql> SELECT min(jahr) as minjahr > -> FROM wiealt > -> WHERE baldwin > 100000; > +---------+ > | minjahr | > +---------+ > | 1950 | > +---------+ > 1 row in set (0.00 sec) > > Mein (reduziertes) PDO-Codeschnipsel sieht so aus: > > $firma = 'baldwin'; > $nummer = 100000; > $query2 = " > SELECT min(jahr) as minjahr > FROM wiealt > WHERE :firma > :nummer"; Wieso nicht in einer Zeile? Eine Aufteilung auf mehrere Zeilen sollte auch eher so aussehen: $query2 = "SELECT min(jahr) as minjahr ". "FROM wiealt ". "WHERE :firma > :nummer"; Siehe auch > $stmt = $dbmerz -> prepare($query2); > $stmt -> bindValue(':firma', $firma, PDO::PARAM_STR); > $stmt -> bindValue(':nummer', $nummer, PDO::PARAM_INT); > $stmt -> execute(); > $result2 = $stmt->fetchAll(PDO::FETCH_OBJ); > if($result2) > { > $max=$result2[0]->minjahr; > var_dump($result2); > } > print "

Max = $max.

"; > > Die unerwartete Ausgabe: > array(1) { [0]=> object(stdClass)#86 (1) { ["minjahr"]=> NULL } } > Notice: Undefined variable: min in > /var/www/html/merz-klaviere.de/service/wie_alt.php on line 180 Welche Zeile ist 180 in dem obigen Beispiel? -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de