PHP乱码的有关问题【注:不是连接数据库乱码】
PHP乱码的问题【注:不是连接数据库乱码】
环境:XP系统, PHP 5.3.4, Apache web server 2.2, mysql 5.5
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> try{ $mysqli = new mysqli("localhost","username","password","db1",3306); //当mysql服务没开启时... if($mysqli->connect_errno){ //注:SqlException是直接继承Exception的自定义类。 // echo $mysqli->connect_error; //乱码的来源... throw new SqlException($mysqli->connect_error,$mysqli->connect_errno); } }catch(SqlException $e){ echo $e->getMessage(); //乱码 }
当mysql数据库服务没启动的时候,上面的php语句输出一堆乱码(错误号:2002)……
网上有调用$mysqli->query("set names gbk")等的需要使用$mysqli对象的都不行,因为$mysqli都还没连接,调用其它函数会报错……
(mysql数据库正常启动后,其它数据库连接错误显示的却是英文,不再出现乱码了……)
怀疑是XP系统下语系设置的问题,导致$mysqli->connect_error返回中文,结果变乱码了……但其它类型的数据库错误($mysqli->error)返回的却是英文……
请问下这种情况怎么处理啊?
先谢谢了~
------解决方案--------------------
在网页上吗? 先改变一下页面编码(浏览器菜单上)看看到底是什么编码及内容, utf8或gbk,
然后如果connect_errno=2002就自己转一下编码...
也可以用自己的message代替该信息....
------解决方案--------------------
------解决方案--------------------
是的 确实 这样
------解决方案--------------------
首先是你PHP的网页头文的显示的编码
然后记得set name UTF-8 或者GBK 或者GB2312 但是要和网页头里的一样
------解决方案--------------------
2002 就是 Can't connect to local MySQL server through socket '/tmp/mysql.sock'
所以你完全可以不细究.
应该和你的mysql client api的版本及设置有关
实在想知道可以照楼上唠叨说的把信息贴上来
------解决方案--------------------
今天学了,,想应该是你下载的数据库,不对汉字处理 啊,,记得是,一个是 V6 版本,还有一个是v9
------解决方案--------------------
用记事本打开文件 然后点:文件-另存为-编码选择UTF-8 最后就OK啦
------解决方案--------------------
又见乱码问题……你确认所有的文件格式都是UTF-8,页面字符集也是UTF-8么?
------解决方案--------------------
gbk 编码的:由于目标机器积极拒绝,无法连接。
mysql 客户端会根据你所使用的操作系统的默认语言产生本地化的错误信息

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
