lundi 20 avril 2015

How to insert proper UTF-8 text into Sqlite3 from PHP?

I'm trying the straightforward way and am getting garbled text:

PHP

<?php
$db = new SQLite3(__DIR__ . "/txttest.db");
$db->exec("CREATE TABLE IF NOT EXISTS txttest (txt TEXT)");

$db->exec("DELETE FROM txttest");

$text = "ção";

$stmt = $db->prepare("INSERT INTO txttest (txt) VALUES (?)");
$stmt->bindParam(1, $text, SQLITE3_TEXT);
$stmt->execute();
?>

Git Bash

sqlite> select * from txttest;
ção

Aucun commentaire:

Enregistrer un commentaire