I'm having issues with getting the data from a table through PDO. The following code appears that it should fetch an associative array, but it returns as a boolean.
$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');
$ps = $pdo->prepare("SELECT * FROM wp_users WHERE user_login = ?");
$ps->execute(array($_GET["user_login"]));
$result = $ps->fetch(PDO::FETCH_ASSOC);
/*extract($result);*/
var_dump($result);
Can someone help me understand how to return an array of values from the database?
EDIT: Here is the code that actually works. However, I'm trying to break it down to understand how it works, then add a second query to the table 'wp_usermeta", then learn how to go to the next step and join the tables instead of running 2 queries. My first step it to see how a smaller part of the code works before moving on to more code.
include ("theme/header-main.html");
$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');
$ps = $pdo->prepare("SELECT * FROM wp_users WHERE user_login = ?");
if (!empty($_GET["user_login"])) {
$ps->execute(array($_GET["user_login"]));
} else {
header('location: index.php');
}
$result = $ps->fetch(PDO::FETCH_ASSOC);
if (is_array($result)) {
extract($result);
include('TESTuser-content.php');
} else {
include('user-content-search.php');
}
include ("theme/footer-main.html");