Options aren't loaded


#1

Hello,

I have a list of options wich is loaded via select2. It worked perfectly. Then I changed the query for security reasons to prepared statements. After that the options weren’t loaded anymore. Is there a known bug with prepared statements? What am I doing wrong?
This is the code:

$dbh = new PDO('mysql:host=127.0.0.1;dbname=eventdb;charset=utf8', 'root', '');
$dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT ed_020_bereich.ED_KBID, ed_020_bereich.BR_Bereich
    FROM ed_020_bereich
    WHERE ed_020_bereich.BR_active = 1 AND ed_020_bereich.ED_KID = :ED_KID
    ORDER BY ed_020_bereich.BR_Bereich";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':ED_KID', $kunde);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$return = array();
while($row = $stmt->fetch())
{
    $return[]=$row;
}

Thanks!


#2

I found the solution.
I had to replace this:

$return[]=$row;

with this:

'id' => $row['ED_KBID'],
'text' => $row['BR_Bereich']

So it’s no select2 bug.