Answer the question
In order to leave comments, you need to log in
Undefined index in array from PDO fetch?
I make a query like
$hero = $pdo->prepare('SELECT * FROM heroes WHERE nickname = :nickname');
$hero->execute(['nickname' => $nickname]);
$hero = $hero->fetch();
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'superheroes';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false);
$pdo = new PDO($dsn, $user, $pass, $opt);
return $pdo;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question