Php adodb connects to MSSQL to solve the garbled Problem

Source: Internet
Author: User
Tags interbase mssql server

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.