Please help me in this code, I don't know why this is drop this error:
Fatal error: Call to a member function fetchAll() on a non-object in D:\Users\Felhasznalo\Desktop\xamppa\htdocs\dart\throwMap.php on line 7
And here is my code:
$p = $_GET['player'];
$pdo = new PDO('mysql:dbname=dart;host=127.0.0.1', 'root', '');
$query = $pdo->prepare("SELECT * FROM dart WHERE player={$p}");
$query = $query->execute();
$result = $query->fetchAll(PDO::FETCH_OBJ);
prepare()call failed. You need to configure PDO to throw exceptions, otherwise it errors silently (and causes things like this)$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);Then work on binding$pcorrectly as a placeholder parameter.$pdo->prepare("SELECT * FROM dart WHERE player=:player");and$query->execute(array(':player' => $p));preparefails theexecutestatement should be throwing the error. I believe the OP is overwriting the prepared statement with the next line$query = $query->execute(). This overwrites$querywith the boolean return value oftrueorfalsefrom theexecutestatement causing the error whenfetchAll()is called on the boolean.$pis a string which isn't quoted) but the much bigger issue is the use of$pdirectly.