0

I try to generate a string with linebreaks, which I want to save in a MySQL-DB

//get some data
while($data = $anything->fetch(PDO::FETCH_OBJ))
    $result .= $data->field.'\r\n';
}

$update = $paed_db->prepare('UPDATE table SET anything = :result WHERE id = :id');
$update->bindParam(':id', $id, PDO::PARAM_INT);
$update->bindParam(':result', trim($result), PDO::PARAM_STR);
$update->execute();

But after reading the result in a textarea, there are no linebreaks but a string which looks like "Lorem\r\nipsum\r\ndolor".

I also tried

$update->bindParam(':result', trim(htmlspecialchars($result)), PDO::PARAM_STR);

What am I doing wrong?

Cœur
  • 34,719
  • 24
  • 185
  • 251
user3142695
  • 13,907
  • 34
  • 141
  • 281

1 Answers1

4

Use "\r\n" (double quotes) since escape sequences aren't interpreted inside of single quotes:

AbraCadaver
  • 77,023
  • 7
  • 60
  • 83