我们有个项目,由不同团队开发。一边用 windows + .net + sql server 2008
;另外一边用linux + yii(php) + mysql
开发,现在用yii
去连接sql server
,开发环境的系统是osx
,yii
用utf-8
,sql 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
,开发环境的系统是osx
,yii
用utf-8
,sql 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
连接和版本情况
现在看下ubuntu环境,freetds是用命令sudo apt-get install freetds-bin
装的,先看图。我的ubuntu服务器是阿里云的,查了系统locale,没有zh_CN.UTF-8
的编码因此先安装这个,这个步骤网络上很多,晚点把链接贴在下面。看到第一张图的版本号是4.2,这是默认装的,为了解决乱码的问题,还要在配置文件里改成7.1,改变客户单编码为UTF-8
,去掉前面的;
,看图。
数据库配置:
<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

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

Dreamweaver Mac版
视觉化网页开发工具

Dreamweaver CS6
视觉化网页开发工具

SublimeText3汉化版
中文版,非常好用