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
  • 37,241
  • 25
  • 195
  • 267
user3142695
  • 15,844
  • 47
  • 176
  • 332

1 Answers1

4

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

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87