Zhou haihan/Wen
Ado can use statements such as new COM ("ADODB. Connection", null, cp_utf8) // 65001 to achieve correct conversion. However, ADO's support for PHP lacks documentation. There is an open-source ADODB with rich documentation.
For different database drivers, the way to set the UTF-8 is also different, as follows:
CopyCode The Code is as follows: for all drivers
'Persistent', 'persistent', 'debug', 'fetchmode', 'new'
Interbase/Firebird
'Did', 'charset', 'buffers', 'role'
M'soft ado
'Charpage'
MySQL
'Clientflags'
Mysqli
'Port', 'socket ', 'clientflags'
Oci8
'Nls _ date_format ', 'charset'
For all drivers
'Persistent', 'persistent', 'debug', 'fetchmode', 'new'
Interbase/Firebird
'Did', 'charset', 'buffers', 'role'
M'soft ado
'Charpage'
MySQL
'Clientflags'
Mysqli
'Port', 'socket ', 'clientflags'
Oci8
'Nls _ date_format ', 'charset'
Where ADO can use the charpage property to set the uft-8, similar to the new COM method. However, it is found that when the $ dbdriver of adonewconnection ($ dbdriver) is set to 'ado 'or 'ado _ MSSQL', the database to be passed in is replaced with provider. How can I set the database name? No way has been found.
$ Dbdriver = 'ado: // SA: cvttdev@172.16.22.40/sqloledb? Charpage = 65001 ';
The format is 'driver: // User: passwd @ host/database? Options [= value]
But it does not solve the problem of setting the database name.
After a long time, you can only find the following solution: Copy code The Code is as follows: <HTML>
<Head>
<Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = UTF-8">
</Head>
<Body>
<? PHP
$ Dbdriver = 'ado _ MSSQL ';
$ Server = '1970. 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 'mongos'
$ 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 "<PRE> ";
Print_r ($ RS-> getrows ());
Print "</PRE> ";
?>
</Body>
</Html>