简体   繁体   中英

Cakephp SQLSTATE[42000]: Syntax error or access violation: 1064

I got this error:

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 'set_origin' at line 1

this error occur when I add this line in my OrderItems controller.

$products = $this->OrderItem->Product->find('all');

and I have no idea what to change.

if i try $products = $this->OrderItem->Product->find('list'); , the error gone. but i need to use find('all') method.

Can anyone help me. thanks in advance.

SET ORIGIN

  1. APP\\Vendor\\dompdf\\include\\stylesheet.cls.php line 218 → Model->__call(string, array)

    'set_origin' array( (int) 0 => (int) 1 )

2.APP\\Vendor\\dompdf\\include\\stylesheet.cls.php line 218 → Style->set_origin(integer)

    else
      $this->_styles[$key] = clone $style;

    $this->_styles[$key]->set_origin( $this->_current_origin );

  }

pdf/default.ctp

<?php  
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php'); 
spl_autoload_register('DOMPDF_autoload'); 
$dompdf = new DOMPDF(); 
$dompdf->set_paper = 'A4';
$dompdf->set_paper("a4", "landscape");
$dompdf->load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
$dompdf->render();
echo $dompdf->output();

ERROR.LOG

2014-02-03 09:29:17 Error: [PDOException] 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 'set_origin' at line 1
Request URL: /mall/orderItems/receipt_pdf/201.pdf
Stack Trace:
#0 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(460): PDOStatement->execute(Array)
#1 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(426): DboSource->_execute('set_origin', Array)
#2 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(666): DboSource->execute('set_origin', Array, Array)
#3 C:\xampp\htdocs\mall\lib\Cake\Model\Datasource\DboSource.php(611): DboSource->fetchAll('set_origin', Array, Array)
#4 C:\xampp\htdocs\mall\lib\Cake\Model\Model.php(799): DboSource->query('set_origin', Array, Object(Style))
#5 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(218): Model->__call('set_origin', Array)
#6 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(218): Style->set_origin(1)
#7 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(1340): Stylesheet->add_style('html', Object(Style))
#8 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(1077): Stylesheet->_parse_sections('html { ?  displ...')
#9 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\stylesheet.cls.php(307): Stylesheet->_parse_css('/**? * dompdf d...')
#10 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\dompdf.cls.php(535): Stylesheet->load_css_file('C:/xampp/htdocs...', 1)
#11 C:\xampp\htdocs\mall\app\Vendor\dompdf\include\dompdf.cls.php(696): DOMPDF->_process_html()
#12 C:\xampp\htdocs\mall\app\View\Layouts\pdf\default.ctp(8): DOMPDF->render()
#13 C:\xampp\htdocs\mall\lib\Cake\View\View.php(945): include('C:\xampp\htdocs...')
#14 C:\xampp\htdocs\mall\lib\Cake\View\View.php(907): View->_evaluate('C:\xampp\htdocs...', Array)
#15 C:\xampp\htdocs\mall\lib\Cake\View\View.php(535): View->_render('C:\xampp\htdocs...')
#16 C:\xampp\htdocs\mall\lib\Cake\View\View.php(479): View->renderLayout('', 'default')
#17 C:\xampp\htdocs\mall\lib\Cake\Controller\Controller.php(952): View->render(NULL, NULL)
#18 C:\xampp\htdocs\mall\lib\Cake\Routing\Dispatcher.php(194): Controller->render()
#19 C:\xampp\htdocs\mall\lib\Cake\Routing\Dispatcher.php(162): Dispatcher->_invoke(Object(OrderItemsController), Object(CakeRequest), Object(CakeResponse))
#20 C:\xampp\htdocs\mall\app\webroot\index.php(110): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#21 {main}

OrderItem model look like this:

    <?php
App::uses('AppModel', 'Model');
/**
 * OrderItem Model
 *
 * @property Order $Order
 * @property Product $Product
 */
class OrderItem extends AppModel {

/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'id';


    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'Order' => array(
            'className' => 'Order',
            'foreignKey' => 'order_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Product' => array(
            'className' => 'Product',
            'foreignKey' => 'product_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
}

Your problem is most probably a naming conflict, where a class name used in the DOMPDF context is identical to one of your already loaded model classes, judging from the stacktrace and the DOMPDF code, this would be a class called Style .

The fact that the problem only appears when using find('all') , indicates that the problematic model class is somehow related to your Product or Order model (or maybe there are even associations in the AppModel class?), because find('list') explicitly excludes relations (by using recursive = -1 ).

In case you do not have a model class named Style , debug the type of $this->_styles[$key] to figure the exact classname, and then resolve the conflict by renaming the model or the style class (if possible).

I faced the same problem.I have cakephp 2.4.6 version.My local is xampp but server is lampp.I used lower case of all my model class.Such as app/Model/student.php, app/Model/group.php, app/Model/order.php, app/Model/list.php.

When ever I use $this->Model->methodName(); inside my controller,it works fine in my local but gives such "Cakephp SQLSTATE[42000]: Syntax error or access violation: 1064" in server.

As Linux is case sensitive,hence it was unable to create database object with the lowercase model name.Hence it gave PDO related error.

I changed the model names with 1stletter Upper such as below app/Model/Student.php,app/Model/Group.php, app/Model/Order.php, app/Model/List.php.

And my problem was solved.

Plz give feedback if ur problem persist after following the above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM