Guten Morgen,
ich habe folgendes Problem, ich möchte über eine PDO Abfrage 2 Datensätze aus 2 unterschiedlichen Querys auslesen. Aber nur die erste Abfrage liefert Werte zurück, die 2.te Abfrage scheint leere Feldwerte zurück zu liefen.
class DB
{
const DATABASE = 'homomatrix';
const HOST = 'localhost';
const USERNAME = 'root';
const PASSWORD = '@d130913';
static private $pdo;
static public function singleton()
{
if (!is_object(self::$pdo))
{
self::$pdo = new PDO('mysql:dbname=' . self::DATABASE . ';host=' . self::HOST,
self::USERNAME,
self::PASSWORD);
self::$pdo->exec("set names utf8");
}
return self::$pdo;
}
}
/* 'SELECT country_name, country_code_char2, un_region, un_subregion FROM jom_countries WHERE country_name = ´$country´ LIMIT 1' */
$st = DB::singleton()
->prepare(
'select country_name, country_code_char2, un_region, un_subregion ' .
'from jom_countries ' .
'where country_name = :countrycode ' .
'limit 0,1');
$countryCode = $country;
$st->bindParam(':countrycode', $countryCode, PDO::PARAM_STR);
if ($st->execute())
{
while ($row = $st->fetch(PDO::FETCH_OBJ))
{
$value_1 = $row->country_name . ', ' . $row->country_code_char2 . ', ' . $row->un_region . ', ' . $row->un_subregion ;
$k_country_name = $row->country_name;
$k_country = $row->country_code_char2;
$k_un_region = $row->un_region;
$k_un_subregion = $row->un_subregion;
}
}
/* 'SELECT state_subdivision_name, state_subdivision_code FROM jom_states_subdivisions WHERE state_subdivision_name = ´$state´ LIMIT 1' */
$st = DB::singleton()
->prepare(
'select state_subdivision_name, state_subdivision_code ' .
'from jom_states_subdivisions ' .
'where state_subdivision_name = :statecode ' .
'limit 0,1');
$stateCode = $state;
$st->bindParam(':statecode', $stateCode, PDO::PARAM_STR, 10);
if ($st->execute())
{
while ($row = $st->fetch(PDO::FETCH_OBJ))
{
$value_2 = $row->row->state_subdivision_name . ', ' . $row->state_subdivision_code ;
$k_state_name = $row->state_subdivision_name;
$k_state = $row->state_subdivision_code;
}
}
/* Zu Prüfzwecken */
echo "PDO Statement: <br />";
echo "Teil 1:<br />";
echo "VALUE 1: ".$value_1."<br />";
echo "COUNTRYNAME: ".$k_country_name."<br />";
echo "COUNTRY: ".$k_country."<br />";
echo "UN_REGION: ".$k_un_region."<br />";
echo "UN_SUBREGION: ".$k_un_subregion."<br />";
echo "Teil 2:<br />";
echo $value_2."<br />";
echo $k_state_name."<br />";
echo $k_state."<br />";
# Länderkürzel entfernen
$k_neustate = str_replace($k_country."-", "", $k_state);
echo "Neustate:<br />".$k_neustate."Ende PDO Statement.<br /><br />";
flush();
Leider komme ich nicht darauf wo der Fehler liegt. Auch das erzeugen einer 2.ten DB-Class und über diese die Abfrage zu generieren, führte zu keinem Ergebnis?
Für Tips und Hilfestellungen wäre ich dankbar.
Mit freundlichen Grüßen,
Ingo