How to bind SQL variables in php?

How to bind SQL variables in php? I want to bind variables instead of just building SQL strings. Anyway, to do this in php?

MySQL or PostgreSQL answers will help.

thanks

+3
source share
4 answers

There, for example. The PDO .
An introduction to pdo and prepared statements (including related parameters) can be found at http://docs.php.net/pdo.prepared-statements

+8
source

You should read about the improved MySQL extension (MySQLi) at http://php.net/manual/en/book.mysqli.php and in prepared statements

+4

Postgres - pg_query_params ( pg_send_query_params) , .

PDO, .

+2

. , , PDO. sprintf().

PDO

StackOverflow .

Sprintf

$sql = sprintf('SELECT * FROM table WHERE id = %d AND field = %s',
               $id,
               mysql_real_escape_string($value));
0

Source: https://habr.com/ru/post/1724952/


All Articles