顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2017年9月16日 星期六

[MySQL] Error establishing a database connection

太久沒有管 MySQL 就會有奇怪的問題, 所以也不太確定問題的由來, 只能用土法解決

InnoDB: The error means the system cannot find the path specified.
InnoDB: If you are installing InnoDB, remember that you must create
InnoDB: directories yourself, InnoDB does not create them.
InnoDB: Error: could not open single-table tablespace file ./mysql/innodb_index_stats.ibd
InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it. 
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.

先直接講解法好了, 就是在 my.cnf 多設定一行
nnodb_force_recovery = 1

重啟 MySQL 後再註解掉就可以了


參考: http://linux-server-tutorial.blogspot.tw/2014/02/mysql-is-not-starting-operating-system.html





2015年1月13日 星期二

[PHP] 免費電子書 - The Right Way 正體中文板

"PHP The Right Way", 從 Tsung's Blog 看到的, 熱血的人真多, 應該也來貢獻一下吧...

PHP 可以說是很好入門, 但是寫得好不容易的程式, 網路上一堆胡言亂語, 真是要慎讀

2012年9月25日 星期二

[PHP] PHP UTF-8 cheatsheet

要確認PHP的輸出是否為UTF-8,有許多步驟要檢查,不過已經有人整理好了,順便筆記一下吧:

1. Update your database tables to use UTF-8
CREATE DATABASE db_name
 CHARACTER SET utf8
 DEFAULT CHARACTER SET utf8
 COLLATE utf8_general_ci
 DEFAULT COLLATE utf8_general_ci
 ;

ALTER DATABASE db_name
 CHARACTER SET utf8
 DEFAULT CHARACTER SET utf8
 COLLATE utf8_general_ci
 DEFAULT COLLATE utf8_general_ci
 ;

ALTER TABLE tbl_name
 DEFAULT CHARACTER SET utf8
 COLLATE utf8_general_ci
 ;

2. Install the mbstring extension for PHP

3. Configure mbstring
$ vim /path/to/php.ini
mbstring.language             = Neutral ; Set default language to Neutral(UTF-8) (default)
mbstring.internal_encoding    = UTF-8  ; Set default internal encoding to UTF-8
mbstring.encoding_translation = On  ;  HTTP input encoding translation is enabled
mbstring.http_input           = auto  ; Set HTTP input character set dectection to auto
mbstring.http_output          = UTF-8  ; Set HTTP output encoding to UTF-8
mbstring.detect_order         = auto  ; Set default character encoding detection order to auto
mbstring.substitute_character = none  ; Do not print invalid characters
default_charset               = UTF-8  ; Default character set for auto content type header

4. Deal with non-multibyte-safe functions in PHP
$ vim /path/to/php.ini
mbstring.func_overload = 7 ; All non-multibyte-safe functions are overloaded with the mbstring alternatives
change functions
mail()          -> mb_send_mail()
strlen()        -> mb_strlen() 
strpos()        -> mb_strpos()
strrpos()       -> mb_strrpos()
substr()        -> mb_substr()
strtolower()    -> mb_strtolower()
strtoupper()    -> mb_strtoupper()
substr_count()  -> mb_substr_count()
ereg()          -> mb_ereg()
eregi()         -> mb_eregi()
ereg_replace()  -> mb_ereg_replace()
eregi_replace() -> mb_eregi_replace() 
split()         -> mb_split()

5. Sort out HTML entities
add wrapper
/**
 * Encodes HTML safely for UTF-8. Use instead of htmlentities.
 *
 * @param string $var
 * @return string
 */
function html_encode($var)
{
 return htmlentities($var, ENT_QUOTES, 'UTF-8') ;
}

6. Check content-type headers
modify output
header('Content-type: text/html; charset=UTF-8') ;
and
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />

7. Update email scripts
use UTF-8 encoding in text file, and mb_encode_mimeheader() with content

8. Check binary files and strings


reference:
* PHP UTF-8 cheatsheet

2011年12月22日 星期四

[PHP] Warning: date(): ... date_default_timezone_set() ...

如果在code裡面用到date()或time()相關函式,出現以下warning:
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /path/to/code.php on line xx

解決方法就是在php.ini設定timezone
$ vim /path/to/php.ini
date.timezone = "Asia/Taipei"
或是在code裡面date()/time()呼叫前指定timezone
$ vim /path/to/code.php
date_default_timezone_set('Asia/Taipei');

2011年12月13日 星期二

[PHP] XML to Array

網路上找到的,用起來這個最順手,順便備份一下