php adodb连接mssql解决乱码问题_php技巧

WBOY
Release: 2016-05-17 09:32:11
Original
1117 people have browsed it

周海汉/文
ADO可以用 new COM("ADODB.Connection", NULL, CP_UTF8)//65001 这样的语句来实现正确转换。但ADO对php的支持缺乏文档。而有个开源的adodb,文档较为丰富。
其中对不同数据库驱动,设置UTF-8的方法还不一样,如下:

复制代码 代码如下:

For all drivers
'persist', 'persistent', 'debug', 'fetchmode', 'new'
Interbase/Firebird
'dialect','charset','buffers','role'
M'soft ADO
'charpage'
MySQL
'clientflags'
MySQLi
'port', 'socket', 'clientflags'
Oci8
'nls_date_format','charset'
For all drivers
'persist', 'persistent', 'debug', 'fetchmode', 'new'
Interbase/Firebird
'dialect','charset','buffers','role'
M'soft ADO
'charpage'
MySQL
'clientflags'
MySQLi
'port', 'socket', 'clientflags'
Oci8
'nls_date_format','charset'

其中,Ado可以使用charPage这个属性来设置uft-8,类似new COM的方式。但发现当将AdoNewConnection($dbdriver)的$dbdriver设为'ado'或'ado_mssql'时,其传进去的database被替换为provider。那database的名字如何设置呢?一直没找到办法。
$dbdriver='ado://sa:cvttdev@172.16.22.40/sqloledb?charpage=65001';
其格式是'driver://user:passwd@host/database?options[=value]
但没解决设置数据库名字的地方。
痛苦了很久,只能找到如下的办法解决:
复制代码 代码如下:






$dbdriver='ado_mssql';
$server='192.168.22.40';
$user='sa';
$password='passwd';
$DATABASE='sugarcrm_db';
$database='sqloledb';
//$dbdriver='ado://sa:cvttdev@172.16.22.40/sqloledb?charpage=65001';
$myDSN="PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER={172.16.22.40};DATABASE=sugarcrm_db;UID=sa;PWD=cvttdev;";
include('adodb5/adodb.inc.php');
$db = ADONewConnection($dbdriver); # eg 'mysql' or 'postgres'
$db->debug = true;
$db->charPage =65001;
//$db->Connect($server, $user, $password, $database);
$db->Connect($myDSN);
//error:mssql server not support codes below
//$db->Execute("set names 'utf8'");
echo "before query";
$rs = $db->Execute('select * from accounts');
print "
"; <br>print_r($rs->GetRows()); <br>print "
Copy after login
";
?>


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!