www.michalscorner.com what I have recently discovered

4Jan/110

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'");

17Aug/090

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()

  1. Define special characters array
    $special=array("À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ą", "Ç", "Ć", "È", "É", "Ê", "Ë", "Ę", "Ì", "Í", "Î", "Ï", "Ð", "Ł", "Ñ", "Ń", "Ò", "Ó", "Ô", "Õ", "Ö, "Ø", "Ś", "Ù", "Ú", "Û", "Ü", "Ý", "Ż", "Ź", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ą", "ç", "ć", "è", "é", "ê", "ë", "ę", "ì", "í", "î", "ï", "ń", "ð", "ó", "ô", "õ", "ö", "ø", "ś", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "ż", "ź");
  2. Define replacement character (in my case "*" works perfectly fine). You may want to create array to subsidize each character with something more suitable.
    $replace="*";
  3. 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.

1Apr/090

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:

  1. Download sources from PHP.net site
    wget http://cz.php.net/get/php-5.2.9.tar.gz/from/us.php.net/mirror
  2. extract it to temporary location
    gzip -d php-5.2.9.tar.gz
    tar -xvf php-5.2.9.tar

Compiling PHP:

  1. 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
  2. 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
  3. Execute make
    make

Post installation:

  1. Navigate to libraries
    cd /tmp/install/php/php5.2.8/libs
  2. Convert library from static to dinamic
    ar -x libphp5.a
  3. Copy dynamic library to apache modules location
    cp libphp5.so /usr/local/apache2/modules/
  4. 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
  5. Restart apache stack