Connor Nee
Connor Nee

Reputation: 95

PHP PDO fetchObject() returns no data but website loads correctly

I have been using these two pages for reference and to make sure I am doing this right since I am new to PDO and trying it out.

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

PDO fetchObject() after fetchall(). returning false

What I am trying to do:

I am trying to fetch all columns from the table 'players' which has a uid equal to the posted one. (I know there will only be one row returned).

Then I need to display only a few certain columns from that row.

editPlayer.php (code snippet)

$uidPlayer = $_POST['hidden'];

include '../verifyPanel.php';
include '../header/examinerheader.php';

masterconnect();

$sqlPlayer = "SELECT * FROM players WHERE uid=?";
$stmt1 = $db->prepare($sqlPlayer);
$stmt1->execute($uidPlayer);
$player = $stmt1->fetchObject();

$username = $player->name;
$uidPlayer = $player->uid;
$pid = $player->playerid;

masterconnect(); contains the $db which is the connect details and a global variable.

using echo on $username does not show a value at all/

I would appreciate it if someone could point out my mistake.

Upvotes: 0

Views: 95

Answers (1)

u_mulder
u_mulder

Reputation: 54831

Argument of execute is array:

$stmt1->execute([$uidPlayer]);

Upvotes: 2

Related Questions