Yii2: yii\db\Exception 42000 on quotation(') search - yii2

Hi i have problem with Yii2 search model.
when user try to search with quotation (for example it's) this exeption Thrown:
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 's%' )' at line 1
The SQL being executed was:
SELECT COUNT(*) FROM `user` `t` WHERE id in (SELECT user_id from user_profile WHERE nickname like '%it's%' )
Stack trace:
#0 \vendor\yiisoft\yii2\db\Command.php(900): PDOStatement->execute()
#1 \vendor\yiisoft\yii2\db\Command.php(388): yii\db\Command->queryInternal('fetchColumn', 0)
#2 \vendor\yiisoft\yii2\db\Query.php(393): yii\db\Command->queryScalar()
#3 \vendor\yiisoft\yii2\db\ActiveQuery.php(334): yii\db\Query->queryScalar('COUNT(*)', NULL)
#4 \vendor\yiisoft\yii2\db\Query.php(300): yii\db\ActiveQuery->queryScalar('COUNT(*)', NULL)
#5 \vendor\yiisoft\yii2\data\ActiveDataProvider.php(165): yii\db\Query->count('*', NULL)
#6 \vendor\yiisoft\yii2\data\BaseDataProvider.php(147): yii\data\ActiveDataProvider->prepareTotalCount()
#7 \vendor\yiisoft\yii2\base\Component.php(130): yii\data\BaseDataProvider->getTotalCount()
#8 \app\modules\post\views\default\search.php(47): yii\base\Component->__get('totalCount')
#9 \vendor\yiisoft\yii2\base\View.php(325): require('...')
#10 \vendor\yiisoft\yii2\base\View.php(247): yii\base\View->renderPhpFile('...', Array)
#11 \vendor\yiisoft\yii2\base\View.php(149): yii\base\View->renderFile('...', Array, Object(app\modules\post\controllers\DefaultController))
#12 \vendor\yiisoft\yii2\base\Controller.php(378): yii\base\View->render('search', Array, Object(app\modules\post\controllers\DefaultController))
#13 \app\modules\post\controllers\DefaultController.php(94): yii\base\Controller->render('search', Array)
#14 [internal function]: app\modules\post\controllers\DefaultController->actionSearch(''"', NULL, NULL)
#15 \vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)
#16 \vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#17 \vendor\yiisoft\yii2\base\Module.php(454): yii\base\Controller->runAction('search', Array)
#18 \vendor\yiisoft\yii2\web\Application.php(87): yii\base\Module->runAction('post/default/se...', Array)
#19 \vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#20 \app\web\index.php(16): yii\base\Application->run()
#21 {main}
Yii2 can't escape parameters automatic ? Do I have to do it menualy ?
thanks.

Assuming you are looking for it's
You hava a wrong quote sequence
try using escape for inner quotes
SELECT COUNT(*) FROM `user` `t` WHERE id in (SELECT user_id
from user_profile
WHERE nickname like '%it\'s%' )
or use double quote fo like
SELECT COUNT(*) FROM `user` `t` WHERE id in (SELECT user_id
from user_profile
WHERE nickname like ("%it's%" )

Related

timestamp error in mysql while installing magento

i am having an error in mysql while installing magento in server`
currently mysql version is 5.5
a:5:{i:0;s:295:"Error in file: "/home/jobixcoindia/public_html/app/code/local/Ced/CsMarketplace/sql/csmarketplace_setup/mysql4-upgrade-0.0.3-0.0.4.php" - SQLSTATE[HY000]: General error: 1293 Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause";i:1;s:1012:"#0 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(644): Mage::exception('Mage_Core', 'Error in file: ...')
#1 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(437): Mage_Core_Model_Resource_Setup->_modifyResourceDb('upgrade', '0.0.3', '0.0.28')
#2 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(320): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('0.0.3', '0.0.28')
#3 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/App.php(428): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 /home/jobixcoindia/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Model_App->_initModules()
#6 /home/jobixcoindia/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#7 /home/jobixcoindia/public_html/index.php(83): Mage::run('', 'store')
#8 {main}";s:3:"url";s:1:"/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
`
Magento Column for date should be TYPE of DATETIME, like default CURRENT_TIMESTAMP

Magento error : SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded;

i have the following problem and i dont know how to solve it. Frontend and Backend dont work. Has anyone an idear ?
a:5:{i:0;s:458:"SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction, query was: UPDATE `catalogrule` SET `name` = ?, `description` = ?, `from_date` = ?, `to_date` = '2017-07-30', `is_active` = ?, `conditions_serialized` = ?, `actions_serialized` = ?, `stop_rules_processing` = ?, `sort_order` = ?, `simple_action` = ?, `discount_amount` = ?, `sub_is_enable` = ?, `sub_simple_action` = ?, `sub_discount_amount` = ? WHERE (rule_id='17')";i:1;s:3033:"#0 /is/htdocs/wp1158418_XAIH5ALR0L/www/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /is/htdocs/wp1158418_XAIH5ALR0L/www/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /is/htdocs/wp1158418_XAIH5ALR0L/www/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `catalog...', Array)
#4 /is/htdocs/wp1158418_XAIH5ALR0L/www/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `catalog...', Array)
#5 /is/htdocs/wp1158418_XAIH5ALR0L/www/lib/Zend/Db/Adapter/Abstract.php(635): Varien_Db_Adapter_Pdo_Mysql->query('UPDATE `catalog...', Array)
#6 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(433): Zend_Db_Adapter_Abstract->update('catalogrule', Array, 'rule_id='17'')
#7 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Core_Model_Resource_Db_Abstract->save(Object(Mage_CatalogRule_Model_Rule))
#8 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/local/Mirasvit/Action/Model/Observer.php(51): Mage_Core_Model_Abstract->save()
#9 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/local/Mirasvit/Action/Model/Observer.php(24): Mirasvit_Action_Model_Observer->updateStatus()
#10 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Model/App.php(1357): Mirasvit_Action_Model_Observer->onControllerActionLayoutRenderBefore(Object(Varien_Event_Observer))
#11 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Model/App.php(1336): Mage_Core_Model_App->_callObserverMethod(Object(Mirasvit_Action_Model_Observer), 'onControllerAct...', Object(Varien_Event_Observer))
#12 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array)
#13 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Controller/Varien/Action.php(384): Mage::dispatchEvent('controller_acti...')
#14 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Adminhtml/controllers/IndexController.php(82): Mage_Core_Controller_Varien_Action->renderLayout()
#15 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_IndexController->loginAction()
#16 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('login')
#17 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#19 /is/htdocs/wp1158418_XAIH5ALR0L/www/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#20 /is/htdocs/wp1158418_XAIH5ALR0L/www/index.php(83): Mage::run('', 'store')
#21 {main}";s:3:"url";s:17:"/index.php/admin/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}
When externol script is running its apply changes in database for
multiple time, Because of this mysql services is stack. Due to this reason
website stopped working. Then you can changes the innodb lock wait timeout
setting in php.ini file.
innodb_lock_wait_timeout=5000
Delete Cache
Follow below directory,
var/cache
The problem will be resolved.

createCommand ' is appending to query generating Database exception

Below is my query:
\Yii::$app->db->createCommand("INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149")->execute();
It is giving me Exception (Database Exception) with the following query:
INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149'
Updated:
<pre>Exception (Database Exception) 'yii\db\Exception' with message '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 'FROM `schoolwall-50` WHERE ID=149
' at line 1
The SQL being executed was: INSERT INTO `schoolwall-10` SELECT FROM `schoolwall-50` WHERE ID=149&#039
;
in /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/db/Schema.php:615
Stack trace:
#0 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/db/Command.php(789): yii\db\Schema->convertException
(Object(PDOException), 'INSERT INTO `sc...')
#1 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/Wall.php(1317): yii\db\Command->execute()
#2 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/Wall.php(1245): frontend\models\Wall::saveShareWithCommunities
(Array, Object(frontend\models\SharePopupModal))
#3 /var/www/html/OroolaGIT/OroolaPhase1/frontend/models/SharePopupModal.php(58): frontend\models\Wall
::shareWithPrimarySchoolCommunities(Object(frontend\models\SharePopupModal))
#4 /var/www/html/OroolaGIT/OroolaPhase1/frontend/controllers/WallController.php(3726): frontend\models
\SharePopupModal->saveShareWithCommunities()
#5 [internal function]: frontend\controllers\WallController->actionModalSharePopupSubmit()
#6 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array
(Array, Array)
#7 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction-
>runWithParams(Array)
#8 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller-
>runAction('modal-share-pop...', Array)
#9 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module-
>runAction('wall/modal-shar...', Array)
#10 /var/www/html/OroolaGIT/OroolaPhase1/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application-
>handleRequest(Object(yii\web\Request))
#11 /var/www/html/OroolaGIT/OroolaPhase1/frontend/web/index.php(18): yii\base\Application->run()
#12 {main}</pre>
Why is &#039 appending to the query? Can anyone please help.
Missing * try adding
\Yii::$app->db->createCommand("INSERT INTO `schoolwall-10`
SELECT * FROM `schoolwall-50` WHERE ID= 149 ;")->execute();

PDO syntax error, SQLSTATE[42000] [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
I'm getting the following error, and I cannot see the issue. Thanks for any help.
Fatal error: Uncaught exception 'PDOException' with message '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 'unique) VALUES ('XX.XXX.XX.X','03/12/2012','XX.XXX.XX.X - 03/12/2012')' at line 1' in /home/content/07/XXX/html/header.php:11 Stack trace: #0 /home/content/07/XXX/html/header.php(11): PDOStatement->execute(Array) #1 /home/content/07/XXX/html/index.php(15): include('/home/content/0...') #2 {main} thrown in /home/content/07/XXX/html/header.php on line 11
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("d/m/Y");
$unique = $ip." - ".$date;
$data = array($ip, $date, $unique, $date);
$STH1 = $DBH->prepare("INSERT INTO uniques (ip, date, unique) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE date = ?");
$STH1->execute($data);
wrap uniquer with backtick since it is a reserved keyword
eg
INSERT INTO uniques (ip, date, `unique`) ...
MySQL Reserved Keyword List

Why I do get [ERR] 1052 - Column 'RECNO' in group statement is ambiguous (MySQL)

I couldn't understand why Column 'RECNO' in group statement is ambiguous
[SQL] SELECT `d`.`FATURA_DURUM` AS `FATURA_DURUM`,
`i`.`RECNO` AS `RECNO`,
`i`.`BOLGE` AS `BOLGE`,
`m`.`MUSTERI_UNVANI` AS `MUSTERI_UNVANI`,
`i`.`MUSTERI_NO` AS `MUSTERI_NO`,
`i`.`HAKEDIS_ONAY_PERSONEL` AS `HAKEDIS_ONAY_PERSONEL`,
`i`.`ISEMRI_NO` AS `ISEMRI_NO`,
`s`.`ADRES_EMAIL` AS `ADRES_EMAIL`,
`i`.`RECNO` AS `ISEMRI_RECNO`,
`i`.`SERVIS_BAS_TAR` AS `SERVIS_BAS_TAR`,
`i`.`SERVIS_BIT_TAR` AS `SERVIS_BIT_TAR`,
`i`.`URUN_CIHAZ_ADI` AS `URUN_CIHAZ_ADI`,
`i`.`URUN_MARKA_ADI` AS `URUN_MARKA_ADI`,
`i`.`URUN_MODEL_ADI` AS `URUN_MODEL_ADI`,
`i`.`ONAY_DURUM` AS `ONAY_DURUM`,
`i`.`HAKEDIS_DURUM` AS `HAKEDIS_DURUM`,
`i`.`HAKEDIS_FATURANO` AS `HAKEDIS_FATURANO`,
`i`.`URUN_SERI_NO` AS `URUN_SERI_NO`,
`s`.`FIRMA_UNVANI` AS `FIRMA_UNVANI`,
`i`.`YAPILANLAR_M` AS `YAPILANLAR`,
st.serino_count
FROM (((`isemri` `i`
left join `musteri_tan` `m` on ((`i`.`MUSTERI_RECNO` = `m`.`RECNO`)))
join `isemri_det` `d` on ((`i`.`RECNO` = `d`.`ISEMRI_RECNO`)))
join `servisler` `s` on ((`i`.`BOLGE` = `s`.`BOLGE_NO`)))
left join
(select URUN_SERI_NO as URUN_SERI_NO2, count(*) as serino_count from ISEMRI
group by URUN_SERI_NO) as st on (st.URUN_SERI_NO2 = i.URUN_SERI_NO) WHERE 1 = 1 and `i`.HAKEDIS_DURUM=0 and `i`.ONAY_DURUM != 1 and (`i`.SERVIS_BAS_TAR between '2011-02-01 00:00:00' and '2011-09-19 23:59:59' ) and `i`.BOLGE=710 group by `i`.`RECNO`,
`m`.`MUSTERI_UNVANI`,
`i`.`MUSTERI_NO`,
`i`.`ISEMRI_NO`,
`i`.`SERVIS_BAS_TAR`,
`i`.`SERVIS_BIT_TAR`,
`i`.`URUN_CIHAZ_ADI`,
`i`.`URUN_MARKA_ADI`,
`i`.`URUN_MODEL_ADI`,
`i`.`ONAY_DURUM`,
`i`.`HAKEDIS_DURUM`,
`i`.`HAKEDIS_FATURANO`
and ( (FATURA_DURUM LIKE '%ayten%' OR RECNO LIKE '%ayten%' OR FIRMA_UNVANI LIKE '%ayten%' OR MUSTERI_UNVANI LIKE '%ayten%' OR SERVIS_BAS_TAR LIKE '%ayten%' OR SERVIS_BIT_TAR LIKE '%ayten%' OR URUN_CIHAZ_ADI LIKE '%ayten%' OR URUN_MARKA_ADI LIKE '%ayten%' OR URUN_MODEL_ADI LIKE '%ayten%' OR ONAY_DURUM LIKE '%ayten%' OR HAKEDIS_DURUM LIKE '%ayten%' OR serino_count LIKE '%ayten%' OR HAKEDIS_FATURANO LIKE '%ayten%' OR URUN_SERI_NO LIKE '%ayten%' OR YAPILANLAR LIKE '%ayten%') ) order by `i`.RECNO desc
[Err] 1052 - Column 'RECNO' in group statement is ambiguous
Edit: The above code is from Navicat. Here is the error from PHP:
<br />
<b>Fatal error</b>: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'RECNO' in group statement is ambiguous' in D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement\Pdo.php:238
Stack trace:
#0 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Adapter\Abstract.php(467): Zend_Db_Statement->execute(Array)
#2 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Adapter\Pdo\Abstract.php(235): Zend_Db_Adapter_Abstract->query('SELECT `d`.`FAT...', Array)
#3 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\DoDb.php(260): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `d`.`FAT...')
#4 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\DoDb.php(163): DoDb::printJsonDG('SELECT `d`.`FAT...', Object(Zend_Db_Adapt in <b>D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement\Pdo.php</b> on line <b>238</b><br />
You're having an occurrence of "RECNO" in your query without a table alias in front of it.
Seeing there are multiple tables in your query (for instance m and i) that have the field RECNO in it; probably a later RECNO (I see one in the last and, where you put OR RECNO LIKE '%ayten%'; which might need one of those aliases.
It might be a good practice to use the aliases in front of every field at all times; it avoids these errors, and you can easily see where the fields come from :).