Connect phpadodb to mssql to solve the garbled problem _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags interbase mssql server
Connect phpadodb to mssql to solve the garbled problem. Zhou Hai Hanwen ADO can use statements such as newCOM (ADODB. Connection, NULL, CP_UTF8) 65001 to achieve correct conversion. However, ADO's support for php lacks documentation. There is an open-source adodb file, 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:

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:

The code is as follows:







$ 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"

"; 
print_r($rs->GetRows());
print "
";
?>


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, document...

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.