The SQL statement generated by the thinkphp3.2 View model prompts 1267 error ~ Query using the TP3.2 View model
This is written in the model.
PicViewModel. class. php
array('picTitle','picToken','picCategroy','picAuthor','picPostTime','_as'=>'Picture'), 'PictureAttachment' =>array('pictureid','pictureurl','creattime','_on'=>'Picture.picToken = PictureAttachment.pictureid','_as'=>'PictureAttachment'), );}
Write controller like this
public function Pic(){ $PicModel =D('PicView'); $s1= $PicModel->field('picTitle,picCategroy,picAuthor,picPostTime,pictureurl')->order('picPostTime desc')->select(); dump($PicModel->getLastSql()); dump($s1); }
The generated SQL statement is as follows:
SELECT Picture.picTitle AS picTitle,Picture.picCategroy AS picCategroy,Picture.picAuthor AS picAuthor,Picture.picPostTime AS picPostTime,PictureAttachment.pictureurl AS pictureurl FROM xxx_picture Picture JOIN xxx_picture_attachment PictureAttachment ON Picture.picToken = PictureAttachment.pictureid ORDER BY Picture.picPostTime desc
Running in phpmyadmin
MySQL return: document
#1267-Illegal mix of collations (utf8_general_ci, IMPLICIT) and (utf8_unicode_ci, IMPLICIT) for operation '='
This should be because the sorting rules are different. then I directly modify the table in phpmyadmin.
It is utf8_general_ci, and an error is returned.
I checked it online.
Alert xxx_picture_attachment convert to character set utf8 COLLATE utf8_general_ci
ALTER xxx_picture_attachment default character set utf8_general_ci
It does not seem to work either.
Error
MySQL return: document
#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 'alert xxx_picture_attachment convert to character set utf8 COLLATE utf8_general _ 'at line 1
Please give me some advice.
Reply to discussion (solution)
Paste the table structure
Paste the table structure
Thank you for reminding me that it was a field sorting problem. thank you ~