网上有不少相关的信息,有部分文章已经相当不错了,但是还是并不能正确的写入记录,或者说只能兼容比较老的版本(具体是之前哪个版本,还并不知晓)(本文描述的内容,是可以适用于EmpireCMS7.2的),比如有一种说法,只需要修改:phome_ecms_news(一次insert,一次update),phome_ecms_news_data_1(一次insert)两张表,现实是如果只操作这两张表,一般都会出现如下的错误:
而且在删除数据的时候,一样会报一些数据库方面的错误。这种情况下唯一的办法就是查看清楚,每一条新录入的数据,在录入过程中,到底对数据库操作了什么?
打开SQL语句日志功能,可以查看在执行添加一条新信息的时候,数据库到底做了哪些操作,
SET GLOBAL log_output = 'TABLE';SET GLOBAL general_log = 'ON';(记得之后要关闭,不然会产生太多不必要的日志文件)
执行完成后,发现新增记录过程中,所有执行过的SQL语句如下:
mysql> SELECT * from mysql.general_log ORDER BY event_time DESC;
+----------------------------+------------------------------+-----------+-----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| event_time | user_host | thread_id | server_id | command_type | argument |
+----------------------------+------------------------------+-----------+-----------+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2018-10-11 13:45:14.338256 | root[root] @ localhost [::1] | 1344 | 1 | Query | SET GLOBAL general_log = 'OFF' |
| 2018-10-11 13:45:09.951519 | root[root] @ localhost [::1] | 1653 | 1 | Quit | |
| 2018-10-11 13:45:09.949531 | root[root] @ localhost [::1] | 1653 | 1 | Query | select andauth from phome_enewsuserloginck where userid='1' |
| 2018-10-11 13:45:09.948513 | root[root] @ localhost [::1] | 1653 | 1 | Query | select userid,groupid,classid,userprikey,uprnd from phome_enewsuser where userid='1' and username='admin' and rnd='og7Q9XlQgP4v7l4Aq1mQ' and checked=0 limit 1 |
| 2018-10-11 13:45:09.947509 | root[root] @ localhost [::1] | 1653 | 1 | Init DB | empirecms |
| 2018-10-11 13:45:09.946506 | root[root] @ localhost [::1] | 1653 | 1 | Query | SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary,sql_mode='' |
| 2018-10-11 13:45:09.945504 | [root] @ localhost [::1] | 1653 | 1 | Connect | root@localhost on using TCP/IP |
| 2018-10-11 13:45:09.888351 | root[root] @ localhost [::1] | 1652 | 1 | Quit | |
| 2018-10-11 13:45:09.886346 | root[root] @ localhost [::1] | 1652 | 1 | Query | select sitename from phome_enewsbefrom |
| 2018-10-11 13:45:09.885342 | root[root] @ localhost [::1] | 1652 | 1 | Query | select writer from phome_enewswriter |
| 2018-10-11 13:45:09.884339 | root[root] @ localhost [::1] | 1652 | 1 | Query | select firsttitlename,isgoodname from phome_enewspublic limit 1 |
| 2018-10-11 13:45:09.883337 | root[root] @ localhost [::1] | 1652 | 1 | Query | select typeid,tname from phome_enewsinfotype where mid='1' order by myorder |
| 2018-10-11 13:45:09.883337 | root[root] @ localhost [::1] | 1652 | 1 | Query | select tempid,tempname from phome_enewsnewstemp order by modid,tempid |
| 2018-10-11 13:45:09.883337 | root[root] @ localhost [::1] | 1652 | 1 | Query | select tempid,tempname from phome_enewsvotetemp order by tempid |
| 2018-10-11 13:45:09.882334 | root[root] @ localhost [::1] | 1652 | 1 | Query | select definfovoteid from phome_enewsclass where classid='2' |
| 2018-10-11 13:45:09.882334 | root[root] @ localhost [::1] | 1652 | 1 | Query | select ttids from phome_enewsclassadd where classid='2' |
| 2018-10-11 13:45:09.880329 | root[root] @ localhost [::1] | 1652 | 1 | Query | select groupid,adminclass from phome_enewsuser where userid='1' limit 1 |
| 2018-10-11 13:45:09.880329 | root[root] @ localhost [::1] | 1652 | 1 | Query | select doall,doselfinfo,doaddinfo,doeditinfo,dodelinfo,docheckinfo,dogoodinfo,dodocinfo,domoveinfo,domustcheck,docheckedit from phome_enewsgrou