Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php pdo and html entity decode

Tags:

php

pdo

The data was inserted into the database after being escaped as follows:

$caller=htmlentities($formVarsI['caller'], ENT_QUOTES, "UTF-8");

Some of the $caller's have single quotes e.g. O'Connor and these then look like O'Connor in the database.

I am now trying to extract the data using a REST api and below is my php:

$sql = "SELECT caller FROM tbl_calls ";
try {
    $db = getConnection();
    $stmt = $db->query($sql);  
    $calls= $stmt->fetchAll(PDO::FETCH_OBJ);
    $db = null;
    echo json_encode($calls);
    }

My question is how to html_entity_decode on $caller so as to remove the

'

for each caller where it applies. Note there are approx. 10,000 entries in the db.

like image 637
Joe Avatar asked Jan 23 '26 06:01

Joe


1 Answers

The solution, of course, is to stop using htmlentities() to escape data going into a database.

The htmlentities() function is for escaping data to be injected into an HTML document context. Not a database.

like image 110
FtDRbwLXw6 Avatar answered Jan 25 '26 20:01

FtDRbwLXw6



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!