lundi 30 janvier 2017

php PDO prepared statements binding and returning as json [duplicate]

This question already has an answer here:

I try to make a prepared statement, bind parameter and execute it on my pdo, however when I run the script in my jquery, json return value is null array

  $tableName='cd';  
   $result = $db->prepare('SELECT * FROM :name');
    $result->bindParam(':name',$tableName,PDO::PARAM_STR);
    $result->execute();
    $data = $result->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($data);

However, when i run the query with 'SELECT * FROM cd' instead of :name it works perfectly fine. Whan can be the reason it does not work?




Aucun commentaire:

Enregistrer un commentaire