How can you organize such a query with PDO bind_param?

There is a dB query:
$stmts = $this->db->prepare("SELECT user_id FROM usersSettings WHERE ?=?");
$stmts->bind_param("ss", $method,$percent);

In the first "?" is the name of the column that should be checked. Alas, this recording method does not show me anything ([num_rows] => 0). If instead of the first ? to write a specific column in a table, all works correctly, how can you ask this column (which must be passed as argument to the function)?
June 8th 19 at 16:35
2 answers
June 8th 19 at 16:37
The third argument to bind_param is the data type of parameter $method. What do you have in this variable?

You want to look like this?
"SELECT user_id FROM usersSettings WHERE ss=$method";

Try this - remove the third parameter.
$stmts = $this->db->prepare("SELECT user_id FROM usersSettings WHERE ?=?");
$stmts->bind_param("ss", $method);
In $method I have a table cell in which it is necessary to make the comparison. That is, I substitute, for example: $method = 'volume';
$percent = 5;
Should be prepared with the bindu: SELECT user_id FROM usersSettings WHERE volume=5
But if you use my code, I have not framed volume in the first "?" - alden73 commented on June 8th 19 at 16:40
and then what "ss"? If the field you stored in the variable $method, and the value of $percent, the result should look like this
$stmts->bind_param($method,$percent); - violet_Dibbe commented on June 8th 19 at 16:43
June 8th 19 at 16:39
In PDO you can't parameterize table names and fields. I.e. the WHERE clause ? = ? or SELECT * FROM table will not work.

Find more questions by tags PHP