2016年12月20日 星期二

PDO transaction

try{ 	 	
$db
->beginTransaction();
 
 $res = .....
if(!$res) throw new Exception(....);
 $db->commit();
}catch (Exception $e){
$db->rollBack();
echo $e->getMessage();
}
------------------------------------------------------
$stmt = $conn->prepare('INSERT INTO my_table(my_id, my_value) VALUES(?, ?)');
$waiting = true; // Set a loop condition to test for
while($waiting) {
    try {
       
$conn->beginTransaction();
        for(
$i=0; $i < 10; $i++) {
           
$stmt->bindValue(1, $i, PDO::PARAM_INT);
           
$stmt->bindValue(2, 'TEST', PDO::PARAM_STR);
           
$stmt->execute();
           
sleep(1);
        }
       
$conn->commit();
       
$waiting = false;
    } catch(
PDOException $e) {
       

           
$conn->rollBack();
            throw
$e;
       
    }
}

2016年10月24日 星期一

jquery 自訂函數

自訂函數
$.fn.xxfunctionName = function() { ***** }

呼叫
$(selector).xxfunctionName(function(){
var selector=$(this);
});

參數問題 foo() , foo(a) , foo(a,b)
function foo(a, b) {   var aa = typeof a !== 'undefined' ? a : 42;   var bb = typeof b !== 'undefined' ? b : 'default_b';   ... }
e.stopPropagation(); 停止父層程序
e.preventDefault(); 停止預設訂做


 $('a[href$="ABC"]')...
= is exactly equal != is not equal ^= is starts with $= is ends with *= is contains ~= is contains word |= is starts with prefix (i.e., |= "prefix" matches "prefix-...")

2016年10月21日 星期五

下載區的限制設定

.htaccess

防止執行,僅限下載
# The following directives prevent the execution of script files
# in the context of the website.
# They also force the content-type application/octet-stream and
# force browsers to display a download dialog for non-image files.

SetHandler default-handler
ForceType application/octet-stream
Header set Content-Disposition attachment

# The following unsets the forced type and Content-Disposition headers
# for known image files:
<FilesMatch "(?i)\.(gif|jpe?g|png)$">
ForceType none
Header unset Content-Disposition
</FilesMatch>

# The following directive prevents browsers from MIME-sniffing the content-type.
# This is an important complement to the ForceType directive above:
Header set X-Content-Type-Options nosniff

# Uncomment the following lines to prevent unauthorized download of files:
#AuthName "Authorization required"
#AuthType Basic
#require valid-user
參考:
http://viralpatel.net/blogs/21-very-useful-htaccess-tips-tricks/
https://github.com/blueimp/jQuery-File-Upload/wiki/Security

2016年10月13日 星期四

table css

單數欄變底色

tr:nth-child(even){background-color: #f2f2f2}

表格防爆框
<div style="overflow-x:auto;">

2016年3月20日 星期日

apache 模組的載入

補充 apache 基本模組,:
alias_module
authz_default_module
authz_host_module
deflate_module
dir_module
expires_module
headers_module
log_config_module
mime_module
php5_module
setenvif_module

先 apachectl configtest 來測試!!

my.cnf 

innodb_buffer_pool_size = 1024M  max_allowed_packet = 5M net_buffer_length = 8K  read_buffer_size = 2M read_rnd_buffer_size = 8M  query_cache_size = 512M myisam_sort_buffer_size = 128M  max_connections = 450 thread_cache = 50 key_buffer_size = 1280M join_buffer_size = 16M  table_cache = 2048 sort_buffer_size = 64M tmp_table_size = 512M max_heap_table_size = 512M  thread_concurrency = 8  log-slow-queries = /daten/mysql-log/slow-log long_query_time = 1 log_queries_not_using_indexes  innodb_additional_mem_pool_size = 64M innodb_log_file_size = 64M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 2 innodb_file_per_table