Why does fetch (PDO::FETCH_ASSOC)
not work properly? How can I get the data I want from the table without a foreach
loop? I have used the $statement
variable before to prepare/execute another query. Could this be the problem?
try
{
$database = new PDO ('mysql:host=localhost;dbname=youdonotneedtoknow;charset=utf8', 'youdonotneedtoknow', 'youdonotneedtoknow');
$database -> setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$database -> setAttribute (PDO::ATTR_EMULATE_PREPARES, true);
//Read
$statement = $database -> prepare ('SELECT * FROM edit');
$statement -> execute ();
while ($row = $statement -> fetch (PDO::FETCH_ASSOC))
{
$windowTitle = $row ['windowTitle'];
$bodyBackgroundColour = $row ['bodyBackgroundColour'];
$divisionBackgroundColour = $row ['divisionBackgroundColour'];
}
}
catch (PDOException $exception)
{
die ('Error: ' . $exception -> getMessage () . '<br><br>' . 'Por favor diríjase a "index.php" en este mismo directorio y contacte a su administrador.');
}