search
HomeBackend DevelopmentPHP Tutorialmysql 插入数据时中文变x87xE7xA7x91xE7x82这种?

mysql;

以下测试 参数都在服务端php文件定义,客户端并不传输;
$sqlstr 数据由adodb读mssql数据库,读出的中文转码:iconv("GBK","UTF-8",$str)

如果直接运行服务器端php文件,直接运行mysql inert 不会出问题

但是如果由客户端post到php,运行mysql 就报错:

Incorrect string value: '\x87\xE7\xA7\x91\xE7\x82...' for column 'typename' at row 1

如果echo $sqlstr 
输出:INSERT INTO dede_arctype SET id ='2001', reid ='1002', topid ='1002', sortrank ='50', typename ='妇科炎症', typedir ='{cmspath}/a' 没问题

直接在mysql-front运行:
  INSERT INTO dede_arctype SET id ='2001', reid ='1002', topid ='1002', sortrank ='50', typename ='妇科炎症', typedir ='{cmspath}/a' 也没问题

这是为什么???

回复讨论(解决方案)

但是如果由客户端post到php,运行mysql 就报错:

Incorrect string value: '\x87\xE7\xA7\x91\xE7\x82...' for column 'typename' at row 1


将你post过来的数据转换一下编码

$typename = iconv("UTF-8", "UTF-8", $typename);


你试试从utf-8转为utf-8

不转码
echo base64_encode($str);
贴出结果

不转码
echo base64_encode($str);
贴出结果

SU5TRVJUIElOVE8gZGVkZV9hcmN0eXBlIFNFVCAgaWQgICAgICAgID0nMTAwMicsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWlkICAgICAgID0nMCcsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0b3BpZCAgICAgID0nMCcsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzb3J0cmFuayAgID0nMCcsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0eXBlbmFtZSAgID0n5oGS55Sf5aaH56eRJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHR5cGVkaXIgICAgPSd7Y21zcGF0aH0vYWhzZmsnLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaXNkZWZhdWx0ICA9JzEnLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVtcGluZGV4ICA9J3tzdHlsZX0vaW5kZXhfYXJ0aWNsZS5odG0nLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGVtcGxpc3QgICA9J3tzdHlsZX0vbGlzdF9hcnRpY2xlLmh0bScsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0ZW1wYXJ0aWNsZT0ne3N0eWxlfS9hcnRpY2xlX2FydGljbGUuaHRtJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5hbWVydWxlICAgPSd7dHlwZWRpcn0ve1l9e019e0R9L3thaWR9Lmh0bWwnLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmFtZXJ1bGUyICA9J3t0eXBlZGlyfS9saXN0X3t0aWR9X3twYWdlfS5odG1sJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uPSfmgZLnlJ/ljLvpmaLlpofnp5Hmi6XmnInkuIDmlK/nlLHlpJrlkI3otYTmt7HkuJPlrrbjgIHkuLvmsrvljLvluIjjgIHkuLvnrqHmiqTluIjnu4TmiJDnmoQuLi4nLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAga2V5d29yZHMgICA9J+a3seWcs+Wmh+enkSzkurrmtYEs55eb57uPLOeUn+auluWZqCzlrqvpoojnlr7nl4Us5aWz5oCnLOeCjueXhyzogr/nmKQs5pu0Li4uJywNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNlb3RpdGxlICAgPSfmgZLnlJ/lpofnp5En

INSERT INTO dede_arctype SET  id        ='1002',                                 reid       ='0',                                 topid      ='0',                                 sortrank   ='0',                                 typename   ='恒生妇科',                                 typedir    ='{cmspath}/ahsfk',                                 isdefault  ='1',                                 tempindex  ='{style}/index_article.htm',                                 templist   ='{style}/list_article.htm',                                 temparticle='{style}/article_article.htm',                                 namerule   ='{typedir}/{Y}{M}{D}/{aid}.html',                                 namerule2  ='{typedir}/list_{tid}_{page}.html',                                 description='恒生医院妇科拥有一支由多名资深专家、主治医师、主管护师组成的...',                                 keywords   ='深圳妇科,人流,痛经,生殖器,宫颈疾病,女性,炎症,肿瘤,更...',                                 seotitle   ='恒生妇科'
数据没有问题
你在插入前有 mysql_query('set names utf8'); 吗?

INSERT INTO dede_arctype SET  id        ='1002',                                 reid       ='0',                                 topid      ='0',                                 sortrank   ='0',                                 typename   ='恒生妇科',                                 typedir    ='{cmspath}/ahsfk',                                 isdefault  ='1',                                 tempindex  ='{style}/index_article.htm',                                 templist   ='{style}/list_article.htm',                                 temparticle='{style}/article_article.htm',                                 namerule   ='{typedir}/{Y}{M}{D}/{aid}.html',                                 namerule2  ='{typedir}/list_{tid}_{page}.html',                                 description='恒生医院妇科拥有一支由多名资深专家、主治医师、主管护师组成的...',                                 keywords   ='深圳妇科,人流,痛经,生殖器,宫颈疾病,女性,炎症,肿瘤,更...',                                 seotitle   ='恒生妇科'
数据没有问题
你在插入前有 mysql_query('set names utf8'); 吗?

$db->Execute("SET NAMES UTF-8");

INSERT INTO dede_arctype SET  id        ='1002',                                 reid       ='0',                                 topid      ='0',                                 sortrank   ='0',                                 typename   ='恒生妇科',                                 typedir    ='{cmspath}/ahsfk',                                 isdefault  ='1',                                 tempindex  ='{style}/index_article.htm',                                 templist   ='{style}/list_article.htm',                                 temparticle='{style}/article_article.htm',                                 namerule   ='{typedir}/{Y}{M}{D}/{aid}.html',                                 namerule2  ='{typedir}/list_{tid}_{page}.html',                                 description='恒生医院妇科拥有一支由多名资深专家、主治医师、主管护师组成的...',                                 keywords   ='深圳妇科,人流,痛经,生殖器,宫颈疾病,女性,炎症,肿瘤,更...',                                 seotitle   ='恒生妇科'
数据没有问题
你在插入前有 mysql_query('set names utf8'); 吗?

$db->Execute("SET NAMES UTF-8");

不转码
echo base64_encode($str);
贴出结果

大哥:插入数据库显示:å­?宫å?…è??ç??这样的乱码,
如果echo $typename;显示:\u4e0d\u80b2\u4e0d\u5b55'\u6210\u529f
这是为什么呢???

$db->Execute("SET NAMES UTF-8"); ???
这就是问题所在!
$db->Execute("SET NAMES UTF8");
mysql 中表示 utf-8 字符集的名字是 utf8 那不是 utf-8
这一特殊情况源于最初的程序员的手误,但已经无法再纠正过来了

对客户端传递到服务端的表单数据实行:urlencode() 编码 URL 字符串

对客户端传递到服务端的表单数据实行:urlencode() 编码 URL 字符串
客户端没有具体数据传递过来,传递的只是操作条件、

$db->Execute("SET NAMES UTF-8"); ???
这就是问题所在!
$db->Execute("SET NAMES UTF8");
mysql 中表示 utf-8 字符集的名字是 utf8 那不是 utf-8
这一特殊情况源于最初的程序员的手误,但已经无法再纠正过来了

非常感谢、好像真是这个问题!!

Statement
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
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.