php+mysql页面乱码问题
一个很小的留言板程序
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> $mysql_server_name = "localhost"; $mysql_username = "root"; $mysql_password = "123456"; $mysql_database = "gbook"; $sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示 $conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password); mysql_select_db($mysql_database,$conn); $result = mysql_query($sql); while($row = mysql_fetch_row($result)) { // ----if语句判断男女------ if($row[2]==1) { $gender = '男';} else { $gender = '女'; }?>
=$row[6]?> =$row[5]?> =$row[1]?>(=$gender?>) =$row[3]?> |
=nl2br($row[4])?> |
} mysql_free_result($result); ?>
结果页面输出是乱码, 页面的编码 也变成了 gb312 原来输入的 是UTF 8
手动将页面编码换成 utf8后 还是有一点乱码出现
应该如何解决??
------解决方案--------------------
数据库,页面,程序。编码一致
------解决方案--------------------
数据库,编辑代码页面,程序,三码一致的,刚开始也遇这问题!
------解决方案--------------------
MySQL+PHP产生乱码原因:
◆ MySQL数据库默认的编码是utf8,如果这种编码与你的PHP网页不一致,可能就会造成MySQL乱码;
◆ MySQL中创建表时会让你选择一种编码,如果这种编码与你的网页编码不一致,也可能造成MySQL乱码;
◆ MySQL创建表时添加字段是可以选择编码的,如果这种编码与你的网页编码不一致,也可能造成MySQL乱码;
◆ 用户提交页面的编码与显示数据的页面编码不一致,就肯定会造成PHP页面乱码;
◆ 如用户输入资料的页面是big5码, 显示用户输入的页面却是gb2312,这种100%会造成PHP页面乱码;
◆ PHP页面字符集不正确;
◆ PHP连接MySQL数据库语句指定的编码不正确。
解决办法参考:http://www.phpnewer.com/index.php/Cjwt/detail/id/558

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
