3

Can anyone figure out why this code isnt printing the value to the page?

$query_params = array(
            ':test1' => 'test1',
            ':test2' => 'test2'
);

// Count the number of records matching the first quota

$quota1Count = "SELECT COUNT(*)
               FROM :test1
               WHERE :test2 = 1";

try { 

        $stmt = $db->prepare($quota1Count); 
        $stmt->execute($query_params); 

    } 

catch(PDOException $ex) { 

        die("Failed to run query"); 
    } 

$quota1 = $stmt->fetchColumn();

Printing to the page

Quota 1: <?= $quota1; ?>

When I dont use the PDO placeholders the code runs fine and returns the correct value:

$quota1Count = "SELECT COUNT(*)
               FROM test1
               WHERE test2 = 1";
d.abyss
  • 204
  • 1
  • 4
  • 26

0 Answers0