|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-14 04:20 UTC] fmate144 at gmail dot com
Description:
------------
I have a simple sqlite database file. If in its path is non ASCII characters, the PDO can not open it!
Reproduce code:
---------------
<?php
// In c:\x?x\test.php
// Exception: unable to open database file
$db = new PDO('sqlite:test.db3');
// Work good!
$db = sqlite_open('test.db3', 0666, $sqliteerror);
// In c:\xex\test.php both work good.
?>
Expected result:
----------------
unable to open database file
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
Test script: --------------- Create folder (charset windows-1251) C:\тест\test\ In the command line call a command C:\тест\test\> php -r "new PDO('sqlite:test.db');" Expected result: ---------------- Should create a database file Actual result: -------------- Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1] unable to open database file' in Command line code:1 Stack trace: #0 Command line code(1): PDO->__construct('sqlite:test.db') #1 {main} thrown in Command line code on line 1I can confirm this issue for CP-1252 with the reproduce script given by wcode404 (thanks!). When the relative path ("test.db") is expanded to a an absolute path by expand_path[1], the path is not UTF-8 encoded, but later sqlite3_open[2] is called, which expects an UTF-8 encoded filename. Using sqlite3_open16 instead would work for me, but that's likely not an option for portability reasons[3]: | The default encoding will be UTF-8 for databases created using | sqlite3_open() or sqlite3_open_v2(). The default encoding for | databases created using sqlite3_open16() will be UTF-16 in the | native byte order. The same problem affects the SQLite3 extension, too. [1] <https://github.com/php/php-src/blob/php-5.6.10/ext/pdo_sqlite/sqlite_driver.c#L764> [2] <https://github.com/php/php-src/blob/php-5.6.10/ext/pdo_sqlite/sqlite_driver.c#L832> [3] <https://www.sqlite.org/c3ref/open.html>