Thursday, May 04, 2006

Linux: Sendmail

Linux must have direct internet access.

Sendmail is located in /etc/mail
The editable configuration file is sendmail.mc.
The default settings are ok if you don't like to edit the file.
After editing, type the following command:
[root@localhost ~]# make -C /etc/mail

If sendmail-cf is not installed this will generate an error. So install sendmail-cf.
[root@localhost ~]# yum install sendmail-cf

After installation of sendmail-cf, make again. When OK, restart sendmail.
[root@localhost ~]# service sendmail restart

* Using Fedora Core 3

Tuesday, May 02, 2006

MySQL: Creating views and functions

Make sure thet the database user has SUPER Privilege, CREATE VIEWS and CREATE ROUTINE. In SQL Query type the following:

mysql> SET GLOBAL log_bin_trust_routine_creators = 1;

* Using MySQL 5.0.18

PHP: Uploading SJIS files to EUC-JP charset

This is assuming that mb_string is installed. Use iconv for Windows

In php.ini:

[mbstring]
; language for internal character representation.
mbstring.language = Japanese

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
mbstring.internal_encoding = EUC-JP

; http input encoding.
mbstring.http_input = auto

; http output encoding. mb_output_handler must be
; registered as output buffer to function
mbstring.http_output = EUC-JP

; enable automatic encoding translation accoding to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
; portable libs/applications.
mbstring.encoding_translation = On

; automatic encoding detection order.
; auto means
;mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
;mbstring.substitute_character = none;

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
;mbstring.func_overload = 0

In upload.php:

// Set encoding of iconv
iconv_set_encoding('internal_encoding', 'EUC-JP');
iconv_set_encoding('input_encoding', 'SJIS');
iconv_set_encoding('output_encoding', 'EUC-JP');

// Set linux local to japanese
setlocale(LC_ALL, 'ja_JP.EUC-JP');

// Read data from file one row at a time
while (($data = fgets($handle)) !== false) {

// Convert SJIS (or other charset) to EUC-JP
$dataWindows = trim(iconv(mb_detect_encoding($data), _CHARSET.'//TRANSLIT', $data));
$dataLinux = trim(mb_convert_encoding($data, 'EUC-JP', mb_detect_encoding($data)));

}


* Using PHP 5.0.3