Does a field cannot be passed in as a parameter when pdo references passing parameters?
$pdo= new PDO ( 'mysql:host=localhost;dbname=test;', 'root', '123456', array (PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'",PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) );$stmt=$pdo->prepare('select ? from tianya_post where id=1');$stmt->bindValue(1, 'title');$stmt->execute();print_r($stmt->fetch());
The title of the first line of record is: "What about me and my friends"
However, I guess what the result is when the column is an official?
Array
(
[Title] => title
[0] => title
)
Why?
If you use
Select title from tianya_post where id =?
$ Stmt-> bindValue (1, 1 );
You can get the correct title.
Reply to discussion (solution)
The field list is not a parameter!
Http://blog.csdn.net/fdipzone/article/details/22330345
Note the following situations: PDO does not help you prevent SQL injection.
Cannot make placeholders? Instead of a group of values, only the first value of this group of data will be obtained, such:
Select * from table where userid in (? );
If you want to use in? Search. you can use find_in_set () instead.
$ Ids = '1, 2, 3, 4, 5, 6 ';
Select * from table where find_in_set (userid ,?);
A placeholder cannot replace the data table name or column name, for example:
Select * from table order ?;
Cannot make placeholders? Replace any other SQL syntax, such:
Select extract (? From addtime) as mytime from table;