search
HomeBackend DevelopmentPHP Tutorialosx写入sql server正常。linux写入sql server乱码。

我们有个项目,由不同团队开发。一边用 windows + .net + sql server 2008;另外一边用linux + yii(php) + mysql开发,现在用yii去连接sql server,开发环境的系统是osxyiiutf-8sql server上用gbk

osx写入sql server正常。linux写入sql server乱码。

据说跟系统的locale有关!!!

求高手解答。

osx配置如下,utf8放下面会报错,不知道什么原因。

<code>'api' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8',
        'username' => 'username',
        'password' => 'password',
        //'charset' => 'utf8',
    ],
</code>

ubuntu配置如下,utf8放哪一样,程序运行正常,但是写入sql server会乱码。

<code>    'api' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8',
        'username' => 'username',
        'password' => 'password',
        //'charset' => 'utf8',
    ],
</code>

回复内容:

我们有个项目,由不同团队开发。一边用 windows + .net + sql server 2008;另外一边用linux + yii(php) + mysql开发,现在用yii去连接sql server,开发环境的系统是osxyiiutf-8sql server上用gbk

osx写入sql server正常。linux写入sql server乱码。

据说跟系统的locale有关!!!

求高手解答。

osx配置如下,utf8放下面会报错,不知道什么原因。

<code>'api' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8',
        'username' => 'username',
        'password' => 'password',
        //'charset' => 'utf8',
    ],
</code>

ubuntu配置如下,utf8放哪一样,程序运行正常,但是写入sql server会乱码。

<code>    'api' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8',
        'username' => 'username',
        'password' => 'password',
        //'charset' => 'utf8',
    ],
</code>

自己找到方法了。作图记录。

网络上的资料大部分是freetds+PDO unixODBC;因为我是用yii2的,不知道能不能用odbc没去试,yii2的文档里用freetds+PDO dblib,我就用这个了。

先看osx环境,freetds是用命令安装的,再看下系统locale编码情况,然后验证下tsql连接和版本情况

osx写入sql server正常。linux写入sql server乱码。

osx写入sql server正常。linux写入sql server乱码。

osx写入sql server正常。linux写入sql server乱码。

现在看下ubuntu环境,freetds是用命令sudo apt-get install freetds-bin装的,先看图。我的ubuntu服务器是阿里云的,查了系统locale,没有zh_CN.UTF-8的编码因此先安装这个,这个步骤网络上很多,晚点把链接贴在下面。看到第一张图的版本号是4.2,这是默认装的,为了解决乱码的问题,还要在配置文件里改成7.1,改变客户单编码为UTF-8,去掉前面的;,看图。

osx写入sql server正常。linux写入sql server乱码。

osx写入sql server正常。linux写入sql server乱码。

osx写入sql server正常。linux写入sql server乱码。

osx写入sql server正常。linux写入sql server乱码。

数据库配置:

<code>//osx
'api' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'dblib:host=x.x.x.x;dbname=dbname;charset=utf8',
        'username' => 'username',
        'password' => 'password',
        //'charset' => 'utf8', //放这报错
],

//ubuntu
'api' => [
    'class' => 'yii\db\Connection',
    'dsn' => 'dblib:host=x.x.x.x;dbname=dbname',
    'username' => 'username',
    'password' => 'password',
    'charset' => 'utf8',
],
</code>

相关链接:

freetds:http://www.freetds.org/userguide/index.htm
freetds+PDO unixODBC:http://www.open-open.com/lib/view/open1405003628966.html
freetds+PDO unixODBC:http://aseity.blog.163.com/blog/static/16481711200702061211659/
freetds安装:http://www.jxm.cc/blogs/473.html
locate安装:http://www.kuqin.com/zhanz/20120219/318273.html
locale介绍:http://blog.csdn.net/rstevens/article/details/2025410

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 Ubuntu 和其他 Linux 下安装 IDLE Python IDE如何在 Ubuntu 和其他 Linux 下安装 IDLE Python IDEApr 08, 2023 pm 10:21 PM

IDLE(集成开发学习环境Integrated Development and Learning Environment)是一个 ​​Python IDE​​​,由 Python 语言本身编写,在 Windows 中通常作为 ​​Python 安装​​ 的一部分而安装。它是初学者的理想选择,使用起来很简单。对于那些正在学习 Python 的人,比如学生,它可以作为一个很好的 IDE 来开始使用。语法高亮、智能识别和自动补全等基本功能是这个 IDE 的一些特点。你可以随时在官方 ​​文档​​ 中了

聊聊Ubuntu中怎么切换多个 PHP 版本聊聊Ubuntu中怎么切换多个 PHP 版本Aug 30, 2022 pm 07:37 PM

如何在 Ubuntu 中切换多个 PHP 版本?下面本篇文章给大家介绍一下Ubuntu中切换多个 PHP 版本的方,希望对大家有所帮助!

ubuntu怎么重启nginx服务ubuntu怎么重启nginx服务May 23, 2023 pm 12:22 PM

1.使用快捷键【Ctrl+Alt+T】打开终端命令模式。2.可以通过以下方式重启nginx服务。方法一,在nginx可执行目录sbin下,输入以下命令重启/nginx-sreload#重启方法二,查找当前nginx进程号,然后输入命令:kill-HUP进程号,实现重启nginx服务#ps-ef|grepnginx#查找当前nginx进程号]#kill-TERM132#杀死nginx进程,132为nginx进程号

docker内ubuntu乱码怎么办docker内ubuntu乱码怎么办Nov 04, 2022 pm 12:04 PM

docker内ubuntu乱码的解决办法:1、通过“locale”查看本地使用的语言环境;2、通过“locale -a”命令查看本地支持的语言环境;3、在“/etc/profile”文件的结尾处添加“export LANG=C.UTF-8”;4、重新加载“source /etc/profile”即可。

ubuntu php无法启动服务怎么办ubuntu php无法启动服务怎么办Dec 19, 2022 am 09:46 AM

ubuntu php无法启动服务的解决办法:1、在php-fpm.conf里面设置错误日志;2、执行“/usr/sbin/php-fpm7.4 --fpm-config /etc/php/fpm/php-fpm.conf”命令;3、修改php的配置文件注释即可。

Ubuntu如何删除无用的Linux内核Ubuntu如何删除无用的Linux内核May 14, 2023 pm 09:13 PM

查找无用的镜像首先,您可以检查当前使用的内核,您可以通过命令获得信息:uname-aa.例如,它在我的桌面上显示为:复制代码代码如下:magc@magc-desktop:~$uname-aLinuxmagc-desktop2.6.24-19-RT#1SMPpremptRTThu8月21日02:08336003UTC2008i686GNU/Linux然后通过查看这台机器上所有内核的列表来决定哪些需要删除:运行命令:复制代码代码如下:dpkg-get-selections|greplinux例如,我

ubuntu没有php-fpm怎么办ubuntu没有php-fpm怎么办Feb 03, 2023 am 10:51 AM

ubuntu没有php-fpm的解决办法:1、通过执行“sudo apt-get”命令添加php的源地址;2、查看有没有php7的包;3、通过“sudo apt-get install”命令安装PHP;4、修改配置监听9000端口来处理nginx的请求;5、通过“sudo service php7.2-fpm start”启动“php7.2-fpm”即可。

Ubuntu下Nginx如何安装与配置Ubuntu下Nginx如何安装与配置May 17, 2023 am 11:01 AM

1.nginx介绍nginx是一个非常轻量级的http服务器,nginx,它的发音为“enginex”,是一个高性能的http和反向代理服务器,同时也是一个imap/pop3/smtp代理服务器。2.对php支持目前各种web服务器对php的支持一共有三种:(1)通过web服务器内置的模块来实现,例如apache的mod_php5,类似的apache内置的mod_perl可以对perl支持。(2)通过cgi来实现,这个就好比之前perl的cgi,该种方式的缺点是性能差,因为每次服务器遇到这些脚本

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools