关于本站
“最难不过坚持”
本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作
有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339
2346
35
分类目录
最新评论
- :weixiao:
-
- 有啥好的解决方法不 :weiqu:
-
- <script>alert(11)</script>
-
- :kaixin: :haha:
-
- 666 :kaixin:
-
文章标签更多
打开边栏(ESC)
关闭边栏(ESC)
tp5.1中字段别名是汉字,提示错误:Exception in Mysql.php line 149 不支持的数据表达式:编号
代码如下:
$rs = Db::table('users') ->field(['userId'=>'编号','loginName'=>'用户名']) ->where('userId',1) ->find();如果直接执行sql语句,是可以用汉字别名的,如:
$sql = 'select userId as 编号,loginName as 用户名 from users where userId=1'; $rs2 = Db::query($sql);怎么解决呢?
根据提示,我们打开Mysql.php 149行,路径:根目录\thinkphp\library\think\db\builder\Mysql.php
if ($strict && !preg_match('/^[\w\.\*]+$/', $key)) { throw new Exception('not support data:' . $key); }原来是正则验证导致汉字出错,\w匹配字母或数字或下划线,等价于[A-Za-z0-9_],再加上.和*
我们可以在正则中加上汉字,就可以应用汉字别名了,修改如下:
if ($strict && !preg_match('/^[\w\.\*\x7f-\xff]+$/', $key)) { throw new Exception('not support data:' . $key); }
赏


相关推荐
Non-static method think\Config::get() should not be called statically
原来是这样use think\Config;
改成这样use think\facade\Config;
下面是官方手册的解释
配置获取
要使用Config类,首先需要在你的类文件中引入
use think\facade\Config;
或者(因为系统做了类库别名,其实就是调用think\facade\Config)
u...
tp5.1排序表达式错误:field(`goodsId`
tp5.1排序表达式错误:field(`goodsId`
解决方法:
在V5.1.7+版本开始,如果你需要在order方法中使用mysql函数的话,必须使用下面的方式:
Db::table('think_user')
->where('status', 1)
->orderRaw("field(name,'...
评论加载中...
后一篇: THINKPHP5.1模板布局