set UTF8 encoding PHP and MySQL
MySQL settings - my.cnf
[mysqld]
character-set-server = utf8
default-character-set = utf8
skip-character-set-client-handshake
Right after mysql_connect execute before each query
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
special character replacement using php
I had small problem with querying Active Directory for users who's names contain special characters. I decided to use translation table to subsidize special characters wit something different. To achieve it php contanins easy to use function str_replace()
- Define special characters array
$special=array("À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ą", "Ç", "Ć", "È", "É", "Ê", "Ë", "Ę", "Ì", "Í", "Î", "Ï", "Ð", "Ł", "Ñ", "Ń", "Ò", "Ó", "Ô", "Õ", "Ö, "Ø", "Ś", "Ù", "Ú", "Û", "Ü", "Ý", "Ż", "Ź", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ą", "ç", "ć", "è", "é", "ê", "ë", "ę", "ì", "í", "î", "ï", "ń", "ð", "ó", "ô", "õ", "ö", "ø", "ś", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ż", "ź"); - Define replacement character (in my case "*" works perfectly fine). You may want to create array to subsidize each character with something more suitable.
$replace="*"; - Acctuall replacement is done like following
$replaced=str_replace($special, $replace, $string);
Than I was able to query active directory ldap with and get the right details.
php 5.2.8 on AIX 5.3 with mysql support
Tough excercise I would say, definately on the beginning nevertheless I was able to make it. Let me share with you how to compile php 5 with mysql support on 64bit platform running AIX 5.3.
Preparation:
- Download sources from PHP.net site
wget http://cz.php.net/get/php-5.2.9.tar.gz/from/us.php.net/mirror - extract it to temporary location
gzip -d php-5.2.9.tar.gz
tar -xvf php-5.2.9.tar
Compiling PHP:
- Configure
./configure --prefix=/usr/local --enable-module=so --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/apache2/conf --with-png-dir=/opt/freeware/include/libpng/png.h --with-zlib-dir=/opt/freeware/lib --enable-shared --disable-static --with-zlib --with-bz2 --with-libxml-dir=/opt/freeware/include/libxml2 --with-jpeg-dir=/opt/freeware/lib --with-png-dir=/opt/freeware/lib --with-xpm-dir=/opt/freeware/lib --with-freetype-dir=/opt/freeware/lib --with-mysql=/usr/local/mysql - edit pcre_internal.h accordingly to the below output
vi ./ext/pcre/pcrelib/pcre_internal.h*** 562,570 **** /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in environments where these macros are defined elsewhere. */ ! #ifndef FALSE typedef int BOOL; #define FALSE 0 #define TRUE 1 #endif --- 562,572 ---- /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in environments where these macros are defined elsewhere. */ ! #ifndef BOOL typedef int BOOL; + #endif + #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif
- Execute make
make
Post installation:
- Navigate to libraries
cd /tmp/install/php/php5.2.8/libs - Convert library from static to dinamic
ar -x libphp5.a - Copy dynamic library to apache modules location
cp libphp5.so /usr/local/apache2/modules/ - Apply necessary changes to httpd.conf file so, php module will be loaded on startup
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
DirectoryIndex index.html, index.php - Restart apache stack