I am trying to figure out how to convert my script history from mysql_query () to PDO. I have a form with 4 input fields that you can optionally select. This means that depending on what information you are trying to get, you can select 0, 1, 2, 3, 4 fields.
I tried to query db as follows:
$q = $db->prepare('SELECT date,
name,
action
FROM history
WHERE name = :name
AND action = :action');
$q->bindParam(':name', $Name, PDO::PARAM_STR, 20);
$q->bindParam(':action', $Action, $PDO::PARAM_STR, 20);
$q->execute();
But this does not work if I do not have the selected fields and you want to show the whole story.
With mysql_query (), I would just do this:
mysql_query('SELECT date,
name,
action
FROM history
$Name
$Action');
This means that if there is no $ Name or $ Action, they are simply not included in the request.
Should I just copy / paste the old query into $ q = $ db-query ('')? But this type of lesion uses PDO.
user554992
source
share