How to bind SQL variables in PHP?
I want to bind variables instead of just building SQL strings. Anyway to do this in Php?
Either MySQL or PostgreSQL answers would help.
Thanks
Solution 1:
There's e.g. PDO.
An introduction to pdo and prepared statements (including bound parameters) is located at http://docs.php.net/pdo.prepared-statements
Solution 2:
You should read on the MySQL Improved Extension (MySQLi) at http://php.net/manual/en/book.mysqli.php , and on prepared statements
Solution 3:
For Postgres specifically - pg_query_params
(and pg_send_query_params
) is the most primitive form of binding but still very useful.
And then there's PDO but the others already mentioned it.