public function select($select,$table, $where) { $data = $this -> pdo->prepare('SELECT :select FROM :table WHERE :where '); $data -> bindParam(':table',$table); $data -> bindParam(':select',$select); $data -> bindParam(':where',$where); $data ->execute(); return $data; } 
  • one
    you do not design your question in such a way with a description of the problems encountered ..... but in general it is impossible to substitute the prepared variables in place of the table and in the sample between select and from ..... - Alexey Shimansky
  • I need to select the user data with login = $ login i, I just can not understand how to work with prepared variables. did so $ sql = "SELECT login FROM tbl_user WHERE id =?"; $ name = $ this -> pdo -> prepare ($ sql); $ name-> excute (array ($ user)); - Hlud09
  • prepared variables can be substituted only into values ​​... for example, with SELECT in the WHERE condition - where the user can send their data ..... in the INSERT request to substitute into VALUES ........ but dynamically substitute them instead all the rest is impossible .... yes and senseless .......... try reading phpfaq.ru/pdo - Alexey Shimansky

1 answer 1

I think you need to write this:

 public function selectById($id) { $data = $this->pdo->prepare('SELECT `login` FROM `tbl_user` WHERE `id` = :id'); $data->bindParam(':id',$id, \PDO::PARAM_INT); $data->execute(); return $data->fetchAll(); } 

In prepared queries, you cannot dynamically select select and table. Only parameters for search. With queries of the same type, this gives a performance boost if you stored $data in a variable and would not create it every time.

and here is the link on http://phpfaq.ru/pdo

  • Thank! I will sort this out ! - Hlud09