Mysql workbench php adodb connects to mssql to solve the problem of garbled characters

WBOY
Release: 2016-07-29 08:40:02
Original
862 people have browsed it

Zhou Haihan/Text
ADO can use statements like new COM("ADODB.Connection", NULL, CP_UTF8)//65001 to achieve correct conversion. But ADO's support for php lacks documentation. There is open source adodb, which has rich documentation.
The method of setting UTF-8 is different for different database drivers, as follows:

Copy the code The code is 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 the charPage attribute to set uft-8, similar to the new COM method. But I found that when the $dbdriver of AdoNewConnection($dbdriver) is set to 'ado' or 'ado_mssql', the database passed in is replaced by provider. How to set the name of the database? Haven't found a way yet.
$dbdriver='ado://sa:cvttdev@172.16.22.40/sqloledb?charpage=65001';
The format is 'driver://user:passwd@host/database?options[=value]
But it didn't solve it A place to set the database name.
After suffering for a long time, I can only find the following solution:

Copy the code The code is as follows:







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


The above introduces how mysql workbench php adodb connects to mssql to solve the garbled problem, including the content of mysql workbench. I hope it will be helpful to friends who are interested in PHP tutorials.

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