顯示具有 php茶包筆記 標籤的文章。 顯示所有文章
顯示具有 php茶包筆記 標籤的文章。 顯示所有文章

星期一, 10月 03, 2016

[php] Fatal error: Maximum execution time of 30 seconds exceeded 超過最長執行時間錯誤

今天寫批次計算演算法時,
發生了此錯誤 Fatal error: Maximum execution time of 30 seconds exceeded
因為預設php是30秒,所以爆開了。
可以簡單為單一執行的程式加入set_time_limit

set_time_limit(0) //則是無上限

沒事不要設定全域的執行時間:D ,想不開可以在php.ini檔設定。
可以找到max_execution_time的設定屬性

星期日, 9月 25, 2016

[php] PDO 批次插入與更新筆記

記錄批次插入並檢查已存在就更新的寫法



$sql = "INSERT INTO `table` (`id`, `name`) VALUES (?,?),(?,?) ON DUPLICATE KEY UPDATE `name` = VALUES(`name`) ";//將要批次插入的值放到 (?,?),看你要插入幾組
 $values = array(1, "test", 2, "so so");//要插入的值
 $stmt = $this->db->prepare($sql);//建立pdo statment
 $stmt->execute($values);//執行時把要插入的值丟入pdo



http://stackoverflow.com/questions/1176352/pdo-prepared-inserts-multiple-rows-in-single-query

https://gist.github.com/kublaios/007ee6b7b7936c6cd80a

星期一, 7月 25, 2016

[MAMP] 手動變更php版本

如果想要自行變動php版本的話,可以下載php版本後
放置以下目錄


再修正httpd.conf

sudo vim /Applications/MAMP/conf/apache/httpd.conf


開啟後再修正版本模組即可

#LoadModule php5_module        /Applications/MAMP/bin/php/php5.6.10/modules/libphp5.so

#你想要的版本
LoadModule php5_module        /Applications/MAMP/bin/php/php5.6.24/modules/libphp5.so

[MAMP] Mac的php版本改用MAMP的php版本的方法

直接用MAMP來取代mac原本裝裝php5版本,

請參考下面流程,請注意MAMP_PHP改為你要使用的版本號即可

open terminal, type
touch ~/.bash_profile; open ~/.bash_profile
edit as follows below, save, quite and restart terminal or alternately
source ~/.bash_profile
to execute new PATH without restarting terminal
and in the fashion of the DavidYell's post above, also add the following. You can stack various variables by exporting them followed by a single PATH export which I demonstrated below
export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.10/bin
export MAMP_BINS=/Applications/MAMP/Library/bin
export USERBINS=~/bins
export PATH="$USERBINS:$MAMP_PHP:$MAMP_BINS:$PATH"
http://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp-path

星期四, 6月 23, 2016

[php] 用命令提示字元檢查語法是否有誤

今天寫物件發生一些sytax錯誤,
開了display_errors, error_reporting都沒什麼錯誤印出來。
於是直接使用cmd line語法檢查..

php -l UserScoreGradeDAO.class.php 
No syntax errors detected in UserScoreGradeDAO.class.php

就會告訴你錯在哪一行了,真的方便多了。

星期五, 4月 29, 2016

[PHP] Composer 教學筆記

現在寫php一定要會用的套件管理工具composer

安裝

參考一下這篇
http://iambigd.blogspot.tw/2013/07/php-composer.html

快速安裝使用

1. 首先要在專案下建立composer.json,加入你要引用的套件(管理套件相依性)

{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}

2. 然後執行composer install

3. 接著就會在專案下產生composer.lock檔案以及vendor目錄

composer.lock

在首次安裝套件完畢後,會產生這個檔案,裡面記錄了所安裝套件的資訊。這個檔案的真正作用是:如果目錄中有這個檔案,執行安裝時,就不會去搜尋更新的版本,而是依照這個檔案中記錄的版本來安裝。這個設計很重要,因為新版的套件很有可能與目前使用的版本不相容,如果不是使用同樣版本,很難保證系統的穩定。過去在使用pear來管理套件時,如果不注意,就有可能發生升級導致的慘劇。

vendor目錄(預設目錄)

主要含以下內容

  • vender/autoload.php
只要引用這個檔案,就可以載入套件中所有對外公開的類別。

require 'vendor/autoload.php';
  • vender/composer
自動載入的載入器與快取檔

  • 各套件資料夾目錄
依造命名規則/

場景應用注意(From 大澤小木鐵phpconf簡報):


  1. Git只需要加入composer.json 與composer.lock,方便其他成員使用
  2. 請由專案負責人進行composer的第一次安裝與之後的更新
  3. 不要將vendor資料夾送入Git,其他團隊成員應該只要透過composer install安裝
  4. Library的composer.lock不要加入Git




參考

  1. https://speakerdeck.com/jaceju/begining-composer
  2. http://ithelp.ithome.com.tw/question/10136653


星期四, 3月 31, 2016

[Apache] Could not reliably determine the server's fully qualified domain name 錯誤訊息

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

只要在
sudo vim /etc/apache2/apache2.conf

加入ServerName localhost

即可

星期六, 7月 11, 2015

[CI] 記錄一下CI框架新手功能

記錄一些CI框架Seed常用的功能手記,讓日後可以快速回憶 :D
雖然已經是被很多人放棄的技術,不過還是有他方便的地方XD

測試版本

CI 2.x

設定起始的base url

Just overwrite the line in config/config.php with the following:
$config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'].'/';
If you are using the sub folder you can use following code:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = "$root";

設定資料庫


application/config/database.php:

設定啟動的控制器


打開application/config/routes.php:
$route['default_controller'] = 'index';

設定啟動時載入相關的helper


打開application/config/autoload.php:
// $autoload['helper'] = array();
$autoload['helper'] = array('form','url','assets','images','load_view_helper');

星期二, 11月 18, 2014

[PHP] 西元日期轉中文年月日

如果有需要將西元日期轉換的話,可以不用拆解字串的方式。
可參考內建的date函數即可

echo date('Y年n月d日',strtotime('2014-11-18')); 

其他你感興趣的文章

Related Posts with Thumbnails