联系官方销售客服

1835022288

028-61286886

开发框架 版主:迅睿框架研发组
我写一条自定义sql语句,表名用了@#代替,好像执行的时候报错?
类型:迅睿CMS 更新时间:2020-12-07 19:23:36

请问php文件,我写一条自定义sql语句,表名用了@#代替,好像执行的时候报错?@#只能用到模板文件中吗?

sql语句没有问题,我在adminphp下测试过!

\Phpcmf\Service::M()->db->query("UPDATE @#1_news as a,@#1_wgone as b SET b.updatetime ='2020-12-1' where a.title=b.title");

回帖
  • #1楼    迅睿框架创始人
    2020-12-07 14:49:42
    Google Pixel 手机 0
    表名@#只能用在模板的sql标签里面,你在php里面需要写上前缀函数
    满意答案
  • tvv
    #2楼    tvv
    2020-12-07 14:52:10
    Chrome 0
    前缀函数?是完整的数据库表名吗?
  • 黄老邪
    #3楼    黄老邪
    2020-12-07 14:55:48
    Chrome 0
    表前缀是:.$this->prefix.
  • 黄老邪
    #4楼    黄老邪
    2020-12-07 14:56:35
    Chrome 0
    SELECT * FROM `".$this->prefix."member_menu` WHERE
  • 迅睿框架技术-实习
    #5楼    迅睿框架技术-实习
    2020-12-07 14:58:35
    小米手机 0
    \Phpcmf\Service::M()->db->prefix
  • tvv
    #6楼    tvv
    2020-12-07 15:21:55
    Chrome 0
    \Phpcmf\Service::M()->db->query("UPDATE '".$this->prefix."1_news' as a,'".$this->prefix."1_wgone' as b SET b.updatetime ='2020-12-1' where a.id=b.cid");报错,哪里错了呢?CRITICAL - 2020-12-07 15:11:43 --> Using $this when not in object context#SQL:SELECT *FROM `dr_cron`WHERE `id` = 50#URL:http://172.16.12.19/admin.php?c=cron&m=do_add&id=50#AGENT:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36#REFERER:http://172.16.12.19/admin.php?c=cron&m=index
  • 迅睿框架技术-实习
    #7楼    迅睿框架技术-实习
    2020-12-07 15:36:14
    小米手机 0
    明显错了
  • 黄老邪
    #8楼    黄老邪
    2020-12-07 15:41:56
    Chrome 0
    .updatetime ='2020-12-1 错了,这里应该是10位的整数,来是格式化后的时间
  • 黄老邪
    #9楼    黄老邪
    2020-12-07 15:42:15
    Chrome 0
    不是
  • 迅睿框架技术-实习
    #10楼    迅睿框架技术-实习
    2020-12-07 15:42:37
    小米手机 0
    $this->prefix这个写错了,改成五楼的写法
  • tvv
    #11楼    tvv
    2020-12-07 15:44:52
    Chrome 0
    \Phpcmf\Service::M()->db->query("UPDATE '".$this->prefix."1_news' as a,'".$this->prefix."1_wgone' as b SET b.updatetime =unix_timestamp(NOW()) where a.id=b.cid");我改时间格式了,还是报错!
  • 黄老邪
    #12楼    黄老邪
    2020-12-07 15:47:53
    Chrome 0
    我自己的是这样写的

  • 易学习
    #13楼    易学习
    2020-12-07 16:01:57
    Chrome 0
    同意十楼的观点
  • tvv
    #14楼    tvv
    2020-12-07 16:05:56
    Chrome 0
    \Phpcmf\Service::M()->db->prefix(); $sql="UPDATE '".$this->prefix."1_news' as a,'".$this->prefix."1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid"; \Phpcmf\Service::M()->db->query($sql);CRITICAL - 2020-12-07 15:57:21 --> Call to undefined method CodeIgniter\Database\MySQLi\Connection::prefix()
  • 南哥
    #15楼    南哥
    2020-12-07 16:29:55
    Chrome 0
    $sql="UPDATE '".\Phpcmf\Service::M()->db->prefix."1_news' as a,'".$this->prefix."1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid";十楼的方法啊
  • tvv
    #16楼    tvv
    2020-12-07 16:49:30
    Chrome 0
    $sql="UPDATE '".\Phpcmf\Service::M()->db->prefix."1_news' as a,'".$this->prefix."1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid"; $rt = \Phpcmf\Service::M()->db->query($sql);if ($rt) { // 成功} else { //失败 echo \Phpcmf\Service::M()->db->error();}还是这个错误提示CRITICAL - 2020-12-07 16:40:50 --> Using $this when not in object context
  • 夏侯渊
    #17楼    夏侯渊
    2020-12-07 16:54:04
    Chrome 0


    同意十楼的观点
  • tvv
    #18楼    tvv
    2020-12-07 16:58:21
    Chrome 0
    $sql="UPDATE '".\Phpcmf\Service::M()->db->prefix."1_news' as a,'".\Phpcmf\Service::M()->db->prefix."1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid"; $rt = \Phpcmf\Service::M()->db->query($sql);if ($rt) { // 成功} else { //失败 echo \Phpcmf\Service::M()->db->error();} ERROR - 2020-12-07 16:48:37 --> 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 ''1_news' as a,'1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=' at line 1#SQL:UPDATE '1_news' as a,'1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid
  • 易学习
    #19楼    易学习
    2020-12-07 16:59:38
    Chrome 0
    撒比了,sql语法谱写错误了


    先去phpmyadmin工具里面运行一下吧
  • tvv
    #20楼    tvv
    2020-12-07 17:06:14
    Chrome 0
    UPDATE test.dr_1_news as a,test.dr_1_news_form_tet as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid数据库里操作没问题啊!
  • 步兵过河
    #21楼    步兵过河
    2020-12-07 17:07:40
    Chrome 0
    UPDATE test.dr_1_news as a,test.dr_1_news_form_tet as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cidUPDATE '1_news' as a,'1_news_form_tet' as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid你对比啊,少了什么,长度都不一样了,而且还多了‘号
  • tvv
    #22楼    tvv
    2020-12-07 17:20:13
    Chrome 0
    $sql="UPDATE test.dr_1_news as a,test.dr_1_news_form_tet as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid"; $rt = \Phpcmf\Service::M()->db->query($sql);if ($rt) { // 成功} else { //失败 echo \Phpcmf\Service::M()->db->error();}我用原数据库名称放进去都报错,提示执行失败?为啥啊?数据库里是成功的!
  • 易学习
    #23楼    易学习
    2020-12-07 17:27:02
    Chrome 0
    $sql="UPDATE dr_1_news as a,dr_1_news_form_tet as b SET b.qy =unix_timestamp(NOW()) where a.id=b.cid";
    $rt = \Phpcmf\Service::M()->db->query($sql);
    if ($rt) {
       // 成功
    } else {
        //失败
        echo \Phpcmf\Service::M()->db->error();
    }
  • tvv
    #24楼    tvv
    2020-12-07 19:23:36
    Chrome 0
    迅睿框架创始人:谢谢了,我解决了!