我们有个项目,由不同团队开发。一边用 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)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

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

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Atom編輯器mac版下載
最受歡迎的的開源編輯器