CDbException

Hello!

I'm getting this error on 5.0.32-Debian_7etch6-log

CDbConnection failed to open the DB connection: 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 '?' at line 1

On localhost I'm using 5.0.45 and the application is working. Has anybody any idea why it is?

i have a similar problem…

when i add data to my db and if i leave one particular column empty i get this error:

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 4

i don't know why i get this because the default value of this column is NULL.

if i fill it up, then everything works fine.

any ideas this is happening?

thanks

Could you enable logging and show what is the error SQL?

i found the problem :) it was my own stupid mistake :) i just had to edit beforeValidate method and now everything works fine :) thanks anyway

My log is:

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "log" application component

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "request" application component

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "urlManager" application component

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "db" application component

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "coreMessages" application component

2009/05/20 09:30:01 [error] [exception.CDbException] exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[42000]: Syntax error or access violation: 1064 You have a

Stack trace:

#0 /exports/www/orcshop.orc.hu/framework/db/CDbConnection.php(208): CDbConnection->open()

#1 /exports/www/orcshop.orc.hu/framework/db/CDbConnection.php(187): CDbConnection->setActive(true)

#2 /exports/www/orcshop.orc.hu/framework/base/CModule.php(326): CDbConnection->init()

#3 /exports/www/orcshop.orc.hu/framework/base/CApplication.php(338): CModule->getComponent('db')

#4 /exports/www/orcshop.orc.hu/framework/db/ar/CActiveRecord.php(716): CApplication->getDb()

#5 /exports/www/orcshop.orc.hu/framework/db/ar/CActiveRecord.php(1902): CActiveRecord->getDbConnection()

#6 /exports/www/orcshop.orc.hu/framework/db/ar/CActiveRecord.php(552): CActiveRecordMetaData->__construct(Object(ProductMainPage))

#7 /exports/www/orcshop.orc.hu/protected/Models/Shop/ProductMainPage.php(19): CActiveRecord::model('ProductMainPage')

#8 /exports/www/orcshop.orc.hu/protected/Controllers/OnlineController.php(18): ProductMainPage::model()

#9 /exports/www/orcshop.orc.hu/framework/web/actions/CInlineAction.php(32): OnlineController->actionIndex()

#10 /exports/www/orcshop.orc.hu/framework/web/CController.php(279): CInlineAction->run()

#11 /exports/www/orcshop.orc.hu/framework/web/CController.php(257): CController->runAction(Object(CInlineAction))

#12 /exports/www/orcshop.orc.hu/framework/web/CController.php(236): CController->runActionWithFilters(Object(CInlineAction), Array)

#13 /exports/www/orcshop.orc.hu/framework/web/CWebApplication.php(332): CController->run('')

#14 /exports/www/orcshop.orc.hu/framework/web/CWebApplication.php(120): CWebApplication->runController('')

#15 /exports/www/orcshop.orc.hu/framework/base/CApplication.php(133): CWebApplication->processRequest()

#16 /exports/www/orcshop.orc.hu/online_index.php(11): CApplication->run()

#17 {main} REQUEST_URI=/

2009/05/20 09:30:01 [trace] [system.web.CModule] Loading "errorHandler" application component

@csombesz: your problem is about DB connection failure. Could you please show what is your DB connection configuration?

        'db'=>array(

            'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=shop',

            'username'=>'user',

            'password'=>'12345',

            'charset'=>'utf8',

        ),

Try adding the following option to your db connection configuration:

		'emulatePrepare' => true,

Thanx for the help it works now.