Consider the following code:
$sql = "INSERT INTO airports (name) VALUES ('$name')";
Suppose now that $name "Chicago O'Hare" . When you interpolate strings, you get this SQL code:
INSERT INTO airports (name) VALUES ('Chicago O'Hare')
which is poorly formed because the apostrophe is interpreted as an SQL quotation mark, and your request will be erroneous.
Worse things can also happen . In fact, SQL injection was ranked # 1 The Most Dangerous Software Error of 2011 from MITER.
But you should never create SQL queries using string interpolation. Use query with parameters instead.
$sql = 'INSERT INTO airports (name) VALUES ($1)'; $result = pg_query_params($db, $sql, array("Chicago O'Hare"));
source share