CDb Connection and brackets

Make a small component for my Yii application. The code

$connection = Yii::app()->getComponent('db');
$sql = 'SELECT * FROM {{settings}}';
$command = $connection->createCommand($sql); 

causes an error

SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in the SQL syntax; check the manual corresponding to MySQL Server Version for the correct syntax for use next to '{settings}}' at line 1. SQL statement executed: SELECT * FROM {{settings}}

Tell me what went wrong. Can't I use curly braces to escape the table name?

thank

UPDATE:

This seems to be a Yii Query Bulduer bug.

if i use this configuration

'db'=>array(
    'connectionString' => '...',
    'emulatePrepare' => ...,
    'username' => '...',
    'password' => '...',
    'charset' => '...',
    'tablePrefix' => ''
),

pay attention to empty tablePrefix - everything works fine.

. . . , .

+4
1

, , .

'db'=>array(
    'connectionString' => '...',
    'emulatePrepare' => ...,
    'username' => '...',
    'password' => '...',
    'charset' => '...',
    'tablePrefix' => ''
),

tablePrefix - .

, , : tablePrefix (, , , v.1.1.6).

. . . , .

tablePrefix, null (, , CDbCommand::setText() ):

if($this->_connection->tablePrefix!==null && $value!='')
    $this->_text=preg_replace('/{{(.*?)}}/',$this->_connection->tablePrefix.'\1',$value);

, , tablePrefix . , , tablePrefix , :

if (!isset($connection->tablePrefix)) $connection->tablePrefix = '';
+2

Source: https://habr.com/ru/post/1540029/


All Articles