php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56993 utf-8 table-names cause syntax-error
Submitted: 2006-04-28 12:53 UTC Modified: 2007-12-19 09:57 UTC
From: indeyets at gmail dot com Assigned:
Status: Closed Package: PDO_MYSQL (PECL)
PHP Version: 5.1.2 OS: FreeBSD
Private report: No CVE-ID: None
 [2006-04-28 12:53 UTC] indeyets at gmail dot com
Description:
------------
notice: the same thing works just fine in mysql console!

whenever I try to prepare some statement which uses utf-8 named tables (cyrillics in my case) I get mysql syntax-error

Reproduce code:
---------------
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET NAMES utf8");

try {
    $sth = $pdo->prepare("SELECT * FROM `test` WHERE `somecolumn` = :p1");
    echo "query 1 is prepared fine\n";

    $sth2 = $pdo->prepare("SELECT * FROM `тест` WHERE `somecolumn` = :p1");
    echo "query 2 is prepared fine\n";
} catch (PDOException $e) {
    echo "failure: ".$e->getMessage()."\n";
}

Expected result:
----------------
query 1 is prepared fine
query 2 is prepared fine

Actual result:
--------------
query 1 is prepared fine
failure: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':p1' at line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-28 12:56 UTC] indeyets at gmail dot com
for some reason, bugtracker converted russian characters to entities. in my case there are real utf-8 characters
 [2006-04-29 21:48 UTC] wez@php.net
The PDO query parser has no idea that you're using utf-8, so it fails to parse the named placeholder.
The workaround is to not use utf-8 names for now.
 [2007-12-19 09:57 UTC] indeyets at gmail dot com
works for me on 5.2.4
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 22:03:39 2021 UTC