PHP ADODB connection MSSQL solve garbled problem _php skill

Source: Internet
Author: User
Tags interbase mssql mssql server
Zhou Haihan/Wen
ADO can be used with new COM ("ADODB". Connection ", NULL, Cp_utf8)//65001 such a statement to implement the correct conversion. But ADO's support for PHP lacks documentation. And there is an open source ADODB, the document is richer.
In which the different database drivers, set the UTF-8 method is not the same, as follows:
Copy Code code as follows:

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 '

Among them, ADO can use Charpage this property to set uft-8, like new COM way. However, it was found that when the $dbdriver of Adonewconnection ($dbdriver) was set to ' ADO ' or ' Ado_mssql ', the database passed in was replaced by provider. How do you set the name of the database? Never found a way.
$dbdriver = ' ado://sa:cvttdev@172.16.22.40/sqloledb?charpage=65001 ';
Its format is ' driver://user:passwd@host/database?options[=value]
But did not resolve the place where the database name was set.
Suffering for a long time, can only find the following solution:
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<body>
<?php
$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};D atabase=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 "<pre>";
Print_r ($rs->getrows ());
print "</pre>";
?>
</body>

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.