|  |  |  |  |  |  |  |  |  | 
 
        
  
          | とりあえずやりたいことが出来た。 |  |  |  |  |  |  | 
 
        
  
          | LAMPならぬ、LNMP環境出来上がり! |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | php.iniの内容 |  |  |  |  |  |  |  | 
 
        
  
          | root@tc4364:/opt/env/srv/php#  
            
diff php.ini php.ini.bak |  |  | 
 
        
  
          | --- php.ini |  |  |  |  |  |  |  | 
 
        
  
          | +++ php.ini.bak |  |  |  |  |  |  |  | 
 
        
  
          | ; Development Value: Off |  |  |  |  |  |  | 
 
        
  
          | ; Production Value: Off |  |  |  |  |  |  | 
 
        
  
          | ; http://php.net/short-open-tag |  |  |  |  |  | 
 
        
  
          | ;short_open_tag  = Off |  |  |  |  |  |  | 
 
        
  
          | short_open_tag =  On |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ; PHP's default character set is set to  empty. |  |  |  | 
 
        
  
          | ; http://php.net/default-charset |  |  |  |  |  | 
 
        
  
          | ;default_charset =  "iso-8859-1" |  |  |  |  |  | 
 
        
  
          | default_charset  = "UTF-8" |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ;extension=php_ldap.dll |  |  |  |  |  |  | 
 
        
  
          | ;extension=php_mbstring.dll |  |  |  |  |  | 
 
        
  
          | ;extension=php_exif.dll
            
      
            
; Must be  after mbstring as it depends on it | 
 
        
  
          | extension=mysql.so |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | [mbstring] |  |  |  |  |  |  |  | 
 
        
  
          | ; language for internal character  representation. |  |  |  | 
 
        
  
          | ; http://php.net/mbstring.language |  |  |  |  |  | 
 
        
  
          | ;mbstring.language = Japanese |  |  |  |  |  | 
 
        
  
          | mbstring.language  = Japanese |  |  |  |  |  | 
 
        
  
          | ;mbstring.language  = neutral |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ; internal/script encoding. |  |  |  |  |  | 
 
        
  
          | ; Some encoding cannot work as internal  encoding. |  |  |  | 
 
        
  
          | ; (e.g. SJIS, BIG5, ISO-2022-*) |  |  |  |  |  | 
 
        
  
          | ;  http://php.net/mbstring.internal-encoding |  |  |  |  | 
 
        
  
          | ;mbstring.internal_encoding = EUC-JP |  |  |  |  | 
 
        
  
          | mbstring.internal_encoding  = UTF-8 |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ; http input encoding. |  |  |  |  |  |  | 
 
        
  
          | ; http://php.net/mbstring.http-input |  |  |  |  | 
 
        
  
          | ;mbstring.http_input = auto |  |  |  |  |  | 
 
        
  
          | ;mbstring.http_input = On |  |  |  |  |  |  | 
 
        
  
          | mbstring.http_input = auto |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | my.confの内容 |  |  |  |  |  |  |  | 
 
        
  
          | egrep -v ^#  /opt/env/srv/mysql/my.cnf |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | [mysqld_multi] |  |  |  |  |  |  |  | 
 
        
  
          | mysqld
            
     
            
=  /usr/local/mysql/bin/mysqld_safe |  |  |  | 
 
        
  
          | mysqladmin =  /usr/local/mysql/bin/mysqladmin |  |  |  |  | 
 
        
  
          | user
            
       
            
=  multi_admin |  |  |  |  |  |  | 
 
        
  
          | password
            
   
            
= my_password |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | [client] |  |  |  |  |  |  |  |  | 
 
        
  
          | default-character-set=utf8 |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | [mysql] |  |  |  |  |  |  |  |  | 
 
        
  
          | default-character-set  = utf8 |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | [mysqld1] |  |  |  |  |  |  |  | 
 
        
  
          | mysqld
            
     
            
=  /usr/local/mysql/bin/mysqld_safe |  |  |  | 
 
        
  
          | ledir
            
      
            
=  /usr/local/mysql/bin |  |  |  |  |  | 
 
        
  
          | mysqladmin =  /usr/local.mysql/bin/mysqladmin |  |  |  |  | 
 
        
  
          | socket
            
     
            
= /tmp/mysql.sock |  |  |  |  |  | 
 
        
  
          | port
            
       
            
= 3306 |  |  |  |  |  |  |  | 
 
        
  
          | pid-file
            
   
            
= /tmp/hostname.pid |  |  |  |  |  | 
 
        
  
          | datadir
            
    
            
=  /usr/local/mysql/data/mysql |  |  |  |  | 
 
        
  
          | language
            
   
            
=  /usr/local/mysql/share/japanese |  |  |  |  | 
 
        
  
          | user
            
       
            
= tc |  |  |  |  |  |  |  | 
 
        
  
          | default-character-set  = utf8 |  |  |  |  |  | 
 
        
  
          | skip-character-set-client-handshake |  |  |  |  |  | 
 
        
  
          | character-set-server  = utf8 |  |  |  |  |  | 
 
        
  
          | collation-server  = utf8_general_ci |  |  |  |  |  | 
 
        
  
          | init-connect =  SET NAMES utf8 |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | サンプルソース |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | cat /hom
            
e/html/db.php |  |  |  |  |  |  |  |  | 
 
        
  
          | <? |  |  |  |  |  |  |  |  | 
 
        
  
          | Header
            
("Content-type:  text/html; charset=utf-8"); |  |  |  |  |  |  |  |  | 
 
        
  
          | header
            
("Expires:  Sat, 01 Jan 2000 00:00:00 GMT");
              
              
              
// Date in the past |  |  |  |  |  |  |  |  | 
 
        
  
          | header
            
("Last-Modified:  ". gmdate("D, d M Y H:i:s"). " GMT");
              
  
              
// always modified |  |  |  |  |  |  |  |  | 
 
        
  
          | header
            
("Cache-Control:  no-cache, must-revalidate");
              
            
              
// HTTP/1.1 |  |  |  |  |  |  |  |  | 
 
        
  
          | header
            
("Pragma:  no-cache");
              
                                    
              
// HTTP/1.0 |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | echo '
            
<?xml  version="1.0" encoding="UTF-8"?>'; |  |  |  |  |  |  |  |  | 
 
        
  
          | ?> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | <html xm
            
lns="http://www.w3.org/1999/xhtml"  xml:lang="ja" lang="ja"> |  |  |  |  |  |  |  |  | 
 
        
  
          | <head> |  |  |  |  |  |  |  |  | 
 
        
  
          | <meta h
            
ttp-equiv="Content-Type"  content="text/html; charset=utf-8" /> |  |  |  |  |  |  |  |  | 
 
        
  
          | <meta h
            
ttp-equiv="Content-Language"  content="ja" /> |  |  |  |  |  |  |  |  | 
 
        
  
          | </head> |  |  |  |  |  |  |  |  | 
 
        
  
          | <body> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | <? |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | $db=mysq
            
l_connect("localhost","scott","tiger"); |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | // encor
            
ding pattern 1 |  |  |  |  |  |  |  |  | 
 
        
  
          | mysql_se
            
t_charset("utf8",$db); |  |  |  |  |  |  |  |  | 
 
        
  
          | mysql_se
            
lect_db("testdb"); |  |  |  |  |  |  |  |  | 
 
        
  
          | // encor
            
ding pattern 2 |  |  |  |  |  |  |  |  | 
 
        
  
          | //$sql =
            
 "SET NAMES utf8"; |  |  |  |  |  |  |  |  | 
 
        
  
          | //mysql_
            
query($sql); |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | if($_SER
            
VER["REQUEST_METHOD"] == "POST"){ |  |  |  |  |  |  |  |  | 
 
        
  
          | if( !
            
mysql_query("insert  into testtable values($_POST[id],'$_POST[nam]')", $db ) ) { |  |  |  |  |  |  |  |  | 
 
        
  
          | die('Error: ' . mysql_error()); |  |  |  |  |  |  |  |  | 
 
        
  
          | } |  |  |  |  |  |  |  |  | 
 
        
  
          | } |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | $result 
            
= mysql_query("select * from testtable",$db); |  |  |  |  |  |  |  |  | 
 
        
  
          | if (!$re
            
sult) { |  |  |  |  |  |  |  |  | 
 
        
  
          | die(
            
'クエリーが失敗しました。'.mysql_error()); |  |  |  |  |  |  |  |  | 
 
        
  
          | } |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ?> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | <table b
            
order="1" style="border:1px  solid;"> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | <? |  |  |  |  |  |  |  |  | 
 
        
  
          | $ln = 0; |  |  |  |  |  |  |  |  | 
 
        
  
          | while ($
            
row = mysql_fetch_assoc($result)) { |  |  |  |  |  |  |  |  | 
 
        
  
          | echo
            
 '<tr><td>'; |  |  |  |  |  |  |  |  | 
 
        
  
          | $ln 
            
= $row['id']; |  |  |  |  |  |  |  |  | 
 
        
  
          | prin
            
t($ln); |  |  |  |  |  |  |  |  | 
 
        
  
          | echo
            
 '</td><td>'; |  |  |  |  |  |  |  |  | 
 
        
  
          | prin
            
t($row['name']); |  |  |  |  |  |  |  |  | 
 
        
  
          | echo
            
 '</td></tr>'; |  |  |  |  |  |  |  |  | 
 
        
  
          | } |  |  |  |  |  |  |  |  | 
 
        
  
          | mysql_cl
            
ose($db); |  |  |  |  |  |  |  |  | 
 
        
  
          | ?> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | <tr> |  |  |  |  |  |  |  |  | 
 
        
  
          | <td vali
            
gn="top"> |  |  |  |  |  |  |  |  | 
 
        
  
          | <? |  |  |  |  |  |  |  |  | 
 
        
  
          | $ln++; |  |  |  |  |  |  |  |  | 
 
        
  
          | print($l
            
n); |  |  |  |  |  |  |  |  | 
 
        
  
          | ?> |  |  |  |  |  |  |  |  | 
 
        
  
          | </td> |  |  |  |  |  |  |  |  | 
 
        
  
          | <td> |  |  |  |  |  |  |  |  | 
 
        
  
          | <form ac
            
tion="" method="post"> |  |  |  |  |  |  |  |  | 
 
        
  
          | <input n
            
ame="id" type="hidden"  value="<? echo $ln; ?>"> |  |  |  |  |  |  |  |  | 
 
        
  
          | <input n
            
ame="nam" type="text"  value="" /><input type="submit"  value="submit" /> |  |  |  |  |  |  |  |  | 
 
        
  
          | </form> |  |  |  |  |  |  |  |  | 
 
        
  
          | </td> |  |  |  |  |  |  |  |  | 
 
        
  
          | </table> |  |  |  |  |  |  |  |  | 
 
        
  
          | </body> |  |  |  |  |  |  |  |  | 
 
        
  
          | </html> |  |  |  |  |  |  |  |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | ブラウザでhttp://192.168.0.4/db.php |  |  |  |  |  | 
 
        
  
          | テキストボックスに追加してボタンを押すと追加されていくという、簡単なモノです。 |  | 
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
  
          | 再起動しても、漢字を入れても値が残っていればOK。 |  |  |  |  | 
 
        
        ![IF>
 
        
  
          |  |  |  |  |  |  |  |  |  | 
 
        
        ![ENDIF]>