I have an error in a mysql query using php PDO

0

I'm starting PDO and I need to make a query, but I do not do it, I do not know if the problem is with the variables I use in the query or I'm declaring something wrong in my code.

This code is the one of my variables:

foreach ($_POST['ciudades'] as $value) {
  if ($current != $num_countries-1){
     $where2 = $where2 . $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'" . $subclas . "'" . ')' . ' ' . 'OR' . ' '. $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'unica'" . ')' . ' ' . 'OR' . ' ';
  }else{
     $where3 = $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'" . $subclas . "'" . ')' . ' ' . 'OR' . ' '. $where . "'" . $value . "'" . ' ' . 'AND' . ' ' . 'anio = ' . $anio . ' ' . 'AND' . ' ' . 'clas = ' . "'unica'" . ')';
  }$current++;
}

And the code of the query is as follows:

    $q = $pdo->prepare('SELECT * FROM :tipoTarifa2 WHERE :where2 :where3');
    $q ->execute(array("tipoTarifa2"=>$tipoTarifa2,"where2"=>$where2,"where3"=>$where3));
    $result = $q->fetchAll();

    foreach ($result as $data) {
      echo $data["Id"];
    }
    
asked by Rafa FE 07.04.2017 в 20:43
source

1 answer

0

According to what I see in the code, you need in the array of the execute () the two points ": typeTariff2" to set the variables, try to print the errors with $ q-> gtInfoInfo ();

slds

    
answered by 07.04.2017 в 21:07