1

I'm trying to send a list of values and use them as column name in a sql query. However it doesn't work and I don't really know why. I enabled the php warning and the log file doesn't show any error. I tried the sql query in phpMyAdmin and it worked. Also there is no error in my jquery function which sends the array. Can anyone help me?

Here is my php file which gets the array :

$effect = $_GET['effect'];
$effectArray = rtrim(str_repeat("e.? = 't' OR ", count($effect)), "OR ");

$result = $db->prepare("
    SELECT *
    FROM skills s, skill_effect_types e
    WHERE s.id=e.skill_id AND ($effectArray)");
$result->execute($effect);
$result->setFetchMode(PDO::FETCH_OBJ);

Here is the print_r of $result :

PDOStatement Object ( [queryString] => SELECT * FROM skills s, skill_effect_types e WHERE s.id=e.skill_id AND (e.? = 't' OR e.? = 't'))

And here is the print_r of $effect :

Array ( [0] => silence [1] => stun )
loumi
  • 95
  • 2
  • 12

1 Answers1

0

The tables and the colomns in the PDO cannot be replaced.Instead of this you can filter and sanitize the data.One way to do this to to assign shorthand parameters to the function which will run the query.

Please have a look here for a detailed explanation..Thanx

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26