Understand Magic Quotes in PHP
Have you ever heard about magic quotes? Today I have just realize why it must be called magic quotes. My objective was just to install phpMyAdmin on CentOS 4.2. I supposed it should be done in an hour. However, I stucked on generating the configuration file, config.inc.php. The symptom are as follows.
- I could add a server.
- I could save the configuration file.
- Sadly, I couldn’t load the configuration file.
- When activated this configuration file, the error message immediately displayed like it couldn’t contact local MySQL instance via unix socket.
- It turned out that phpMyAdmin couldn’t read config.inc.php, so I directly modified config.default.php.
- phpMyAdmin worked just fine to connect to remote MySQL instant.
- Unfortunately, all single quote characters retrieved from MySQL are escaped by backslash, e.g., \’abc\’ instead of ’abc’ usually.
After investigated for the whole day, I found the problem caused by incorrect configuration in php.ini. Yes, it is magic quotes. That’s why it is called magic quotes. There are 3 magic quotes options;
- magic_quotes_gpc = On
- magic_quotes_runtime = Off
- magic_quotes_sybase = Off
In my case, the problem is magic_quotes_runtime, the correct value should be Off. Unfortunately, it was set to On in my machine. After adjust this value, everything works just fine.
Just a side note, GPC stands for Get/Post/Cookie. So magic_quotes_gpc means that all values extracted from Get/Post/Cookie are automatically quoted.
Technorati Tags: English, IT, HTML, Programming, PHP, Tips and Tricks, Magic Quotes, PhpMyAdmin, MySQL, CentOS
- sugree's blog
- 1625 reads
Post new comment