[Reprint] Using mysqli in php-5.1.4

Source: Internet
Author: User
[Reprint] Using mysqli in php-5.1.4

Author: Piggy Release Date: Views: 65 from: http://www.phpx.com/viewarticle.php? Id = 119200
I have been using PhP4 and have little access to PhP5. Due to the learning needs, I gradually got into touch with PhP5 and learned about the new features of PhP5, MySQL I Extension library, SPL and PDO. Don't laugh. I have little contact with PhP5. In order to be able to use PhP5, I set up a php-5.1.4 mysql-5.0.22 IIS-5.1 runtime environment, install PHP and MySQL more information, here do not repeat. The first goal of my advanced tutorial is mysqli. To use mysqli, you have to go to PhP. add a line of extension = php_mysqli.dll in ini, which is embedded in the ext folder of php5.1.4. Restart the WWW Service to use the mysqli extension Library (some users may need to restart ). After the configuration, use mysqli's Object-Oriented Programming Method to write the following code: [PHP] <? PHP $ db = new mysqli ("localhost", "root", "123456", "test"); $ db-> set_charset ("utf8 "); $ rs = $ db-> query ("select * From 'gallery _ ablum '"); While ($ ROW = $ RS-> fetch_assoc ()) {echo $ row ['name'],"
";}$ RS-> close (); $ db-> close ();?> [/PHP] I am eager to run this code on the website, but I found the script error "using the undefined set_charset function". Does pphp5.1.x no longer support mysqli? So I commented out the second line and found that the program was successfully executed! I am very happy to finally display the data. Although some of the data is garbled (garbled because I used utf8 encoding, and laint1 is used by default for mysqli connections) next, I tried the functions in mysqli and found that most of them are still available. But can't we solve the character set problem? If it cannot be solved, programs encoded with other databases cannot be used. So I tried to replace the statement in the second row with $ db-> query ("set names utf8");, but the execution was successful, but it failed to solve the garbled code as I expected, use echo $ db-> character_set_name (); to check whether the current encoding is laint1. I still don't have to worry about it. I checked the information in php.net and finally learned that php_myqli.dll published in php.net really cannot use this function, but MySQL provides this DLL. Yes: Thanks! We recommend that you use php5.1.4 and mysql5.0.22 for MySQL. Therefore, you can only download these two related connectors. The installation of connector is simple. Stop the WWW Service and overwrite the libmysql. dll file in the root directory and the php_mysqli.dll file in the ext directory. When I opened the browser happily and executed the previous code, the error "unable to load dynamic library php_mysqli.dll, unable to load" appeared. I immediately fainted. Isn't PHP and MySQL really wrong? I am reluctant to give up my PhP5 path, so I checked the information on Google and found that the search results are consistent. DLL, you need to put this library in the PHP path or system32. Libmysql. dll is clearly in my PHP Directory (this libmysql. dll is provided by MySQL connector). Should it be placed in system32? Copy libmysql. DLL to system32, restart and execute PHP, or fail. Later, I checked the information in the technical support of mysql.com to see if I could find some clues. After a lot of browsing, I found someone who said they would use depends to check the software. At first I thought it was a self-developed software. The author made an advertisement here, but then I really have no way, only dead horse as a doctor, go to the http://www.dependencywalker.com to download a depends work, the original thing is a similar to the shell of the software. As a result, I used it to find MySQL connector and used vc7 to compile the DLL. However, my machine does not install the vc7 Runtime Library, so it cannot load php_mysqli.dll. The reason is found, I am on the http://www.dll-files.com/dllindex/dll-files.shtml immediately? Msvcr71 download the msvcr71.dll Runtime Library and copy it to the System32 system directory (by the way, copy the libmysql. after the DLL is deleted, you can keep one copy in the PHP Directory.) restart, browse, and finally execute the new features of MySQL. (Note: To facilitate debugging, I opened PHP. display_errors and display_startup_errors in ini) the above is the whole process I have solved. In essence, there is no need for so many steps. After php5.1.4 is installed, download the MySQL PHP ctor on the MySQL website to overwrite the corresponding files in the PHP Directory. Search for the msvcr71.dll file in your system disk. If the file does not exist in the system directory, download it and put it in the System32 system directory. In addition, if the system is in NTFS format, you must pay attention to the permission issue. In particular, the default permissions for files downloaded from the Internet may be insufficient. If the display_startup_errors parameter is enabled, the unable to load dynamic library ***. dll statement is used to reject access. Now you have to pay attention to the permission issues. For the first time, I am posting this seriously. I mainly want some friends who have just learned mysqli to provide some useful information, rather than discussing whether mysqli is good or not. As a result, I hope to continue to discuss the new features in PhP5, especially in PDO and pear, my mailbox zhiouzhu (AT) gmail.com. Thank you for your advice.

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.