赞
踩
解决方法:
1,下载think-oracle 扩展,资源很多,百度即可下载,分别放置于db下的connector 和 builder 文件夹下
2,安装oracle本地客户端,一搜一大把,核心注意不要下错版本
原因分析:因为远程oracle数据库采用的字符集是ZHS16GBK,我本地的程序是utf8,导致字符串与远程不匹配导致oracle无法查询
解决方法:涉及到中文字符串的,先做转义,然后再代入查询,如下
- public function sup_waite_todu(){
- $text1 = iconv('utf-8', 'gbk','您有新的订单,请及时处理!【');
- $text2 = iconv('utf-8', 'gbk','】【采购员:');
- $text3 = iconv('utf-8', 'gbk','】【数量:');
- $text4 = iconv('utf-8', 'gbk','】');
-
- $effect = $this->db->query("select to_char(post_date,'yyyy-mm-dd hh24:mi:ss')||'".$text1."'||order_id||'".$text2."'||post_person||'".$text3."'|| (select sum(buy_num) from exp_order b where a.order_id = b.order_id and a.hospital_code = b.hospital_code)||'".$text4."' as info from exp_order_master a where a.sup_id = '1076' and a.hospital_code ='1001' and a.order_status='1' order by post_date desc");
- return $effect;
- }
解决方法:
1,三方业务新建一个模型放于common下的model层,初始化直接连接远程,
2,application下的config.php 增加数据库配置
3,注意oracle的端口,需要根据实际情况变更
- <?php
- namespace app\common\model;
-
- use think\Db;
- use think\Model;
- use think\Config;
-
- /**
- * 供应商模型
- */
- header('Content-type: text/html; charset=ZHS16GBK');
- class Sup extends Model
- {
- protected function initialize()
- {
- $this->db = Db::connect(config('db_config1'));
- }
-
- //获取供应商信息
- public function sup_base_info($sup_id=''){
- $effect = $this->db->query("select b.hospital_code,c.f_fullname, a.expire_date,b.sup_name,b.sup_addres,b.sup_phone,b.sup_worker, a.f_createdate from xmadmin.xm_base_user a, exp_sup_dict b, xmadmin.xm_base_company c where a.f_encode = b.sup_id and b.hospital_code = c.f_companyid and a.f_encode='".$sup_id."'");
- return $effect;
- }
- }

- 'db_config1' => [
- // 数据库类型
- 'type' => 'oracle',
- // 数据库连接DSN配置
- 'dsn' => '',
- // 服务器地址
- 'hostname' => '',
- // 数据库名
- 'database' => '',
- // 数据库用户名
- 'username' => '',
- // 数据库密码
- 'password' => '',
- // 数据库连接端口
- 'hostport' => '',
- // 数据库连接参数
- 'params' => [],
- // 数据库编码默认采用utf8
- 'charset' => 'ZHS16GBK',
- // 数据库表前缀
- 'prefix' => '',
- ]

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。