[mysql] 外鍵 Foreign Key 速查

當關聯父資料表的主鍵紀錄行被刪除或修改時,InnoDB 對子資料表中紀錄行的處理方式:
CASCADE – 會將有所關聯的紀錄行也會進行刪除或修改。
SET NULL –
會將有所關聯的紀錄行設定成 NULL
NO ACTION –
有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
RESTRICT –
 NO ACTION 相同。[……]

閱讀更多

[PHP] php7 Call to undefined function curl_init() , fix the issue

Move to Windowssystem32 folder:
libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll

Move to Apache24bin folder
libssh2.dll

Uncomment extension=php_curl.dll

原文
http://php.net/manual/en/curl.installation.php

# PHP.ini取消註解
extension=php_curl.dll

# 移動PHP目錄中的下列檔案至 C:Windowssystem32中
libssh2.dll, php_curl.dll, ssleay32.dll, libeay32.dll
# 移動PHP目錄中的下列檔案至apachebin中
libssh2.dll

[……]

閱讀更多

MIS WAMP手動安裝及設定教學 Apache2.4 + PHP7 for windows10

手動安裝 Apache2.4 + PHP7 for windows10

首先,我該選x64或x86安裝呢?

何謂 x64 和 x86,可閱讀下方網址文章,本篇不多做解釋
x86和x64到底有什麼差異? http://www.ithome.com.tw/node/56880

注意 !!!

若安裝x64版本,PHP & Apache 都需要選擇x64版本,反之亦然

安裝 PHP7 for windows

本例下載 PHP 7.0 VC14 x64 Thread Safe

php-7.0.10-Win32-VC14-x64.zip

解壓縮至 PHP 的存放目錄
本例解壓縮至 C:php-7.0.10-Win32-VC14-x64

設定 php.ini PHP.ini 為PHP的設定檔

PHP安裝目錄中尚無 PHP.ini
但於安裝目錄中有下列2個檔案
php.ini-development 為開發環境用參考設定檔
php.ini-production    為正式環境用參考設定檔
本例複製 php.ini-development 更名為 php.ini 置於於PHP安裝目錄中 文字編輯器開啟 php.ini

以下為常用設定

視需求調整參數,至於設定內容就不於本篇討論

「C:/php-7.0.10-Win32-VC14-x64/」為PHP安裝目錄

注意!!!!!!!!!!

分隔路徑的斜線,要用「/」而不是 windows 檔案總管的「\」

所以是
「C:/php-7.0.10-Win32-VC14-x64/」

不是
「C:\php-7.0.10-Win32-VC14-x64\

儲存 httpd.conf

Apache安裝為 windows 服務,開機自動啟動

開啟 Win10 的 「命令提示字元(系統管理員)」

// 測試設定檔是否正確

錯誤會跳錯誤訊息,正確會顯示syntax OK,接著安裝服務

// 安裝服務,反之解除安裝為 httpd.exe -k uninstall

測試是否正確運行

在網站根目錄C:/AppServ/www下建立一個index.php檔案

運行 http://127.0.0.1
看到下列畫面,代表安裝成功

呼~打完收工!!

[……]

閱讀更多

[SQL] MySQL to PostgreSQL 好痛轉移,SQL語法差異

換資料庫真的好機掰,會有一堆未知問題,見招拆招,紀錄於下

LIMIT OFFSET

/* MySQL */
SELECT * FROM abc WHERE status=1 ORDER BY create_time DESC LIMIT 0 , 10
/* PostgreSQL */
SELECT * FROM abc WHERE status=1 ORDER BY create_time DESC LIMIT 10 OFFSET 0

# UPDATE 不能加 ORDER BY and LIMIT
/* MySQL */
UPDATE abc SET aaa=1 WHERE id<=100 ORDER BY status DESC LIMIT 10

/* PostgreSQL */
/* 若有需求要用子句解決 */
UPDATE abc main SET aaa=1
FROM
 ( SELECT id FROM page_builder WHERE id<=100 ORDER BY status DESC LIMIT 10 ) sub
WHERE main.id = sub.id

PHP

//mysql 取新增的id
mysql_insert_id() mysqli_insert_id();
//PostgreSQL

$re = pg_query($conn, "INSERT INTO foo (bar) values (123);");
$re
= pg_query("SELECT lastval();");
$row
= pg_fetch_row($re);
$insert_id
= $row
[0];

[……]

閱讀更多

[PHP] Fatal error: Uncaught Error: Call to undefined function ldap_connect apache2.4 php7 Windows

因為要用到 PHP  ldap_connect()
Fatal error: Uncaught Error: Call to undefined function ldap_connect()
設定方式網路上很多
主要是設定PHP.ini擴充套件,把前面的註解拿掉

extension=php_imap.dll

如果還不行
Copy PHP 目錄下的 libsasl.dll 到apache中的bin資料夾中

如果還不行
Copy PHP 目錄下的 libeay32.dll 及 ssleay32.dll 到 C:WindowsSystem32 中

基本上該設定的都設定了,但我還是不行,
這是一個怪問題,我用Nginx + PHP7
可以順利的call ldap_connect()
但用 apache2.4 就會跳 Fatal error
怪的是我用相同的PHP7,搞死人,
最後找到原因,以下解決我的問題
修改 PHP.ini

extension_dir = "ext"

改為

extension_dir = "C:/php-7.0.9-Win32-VC14-x64/ext"

也不知道為什麼,用Apache2.4預設的PHP.ini會有這樣的問題,用NginX反而不會
怪怪怪!!!

http://stackoverflow.com/questions/17204437/fatal-error-call-to-undefined-function-mb-detect-encoding

[……]

閱讀更多

[php] json_decode json file to array return NULL

This worked for me

<?php
$json_string = file_get_contents('json_string.txt');
$json_string = preg_replace( '/[^[:print:]]/', '',$json_string);
$obj = json_decode( $json_string , true );
print_r($obj);
exit;
?>

這問題有點見鬼,直接用字串測試,一樣的josn字串,正常,就是放進檔案用json_decode()會拋回個NULL,網路上看了很多方法都沒效,搞了我好久,以下跟大家分享,下方有範例檔

這樣是正常的
<?php
$json_string = '{"aaa":"bbb","0":{"bbb":"bbb","ccc":"ccc"}}';
$obj = json_decode( $json_string , true );
var_dump($obj);
?>
output:
array(2) { ["aaa"]=> string(3) "bbb" [0]=> array(2) { ["bbb"]=> string(3) "bbb" ["ccc"]=> string(3) "ccc" } }
放進檔案就不行
<?php
$json_string = file_get_contents('json_string.txt');
$obj = json_decode( $json_string , true );
var_dump($obj);
exit;
?>
output:
NULL

我覺得應該是檔案中有些隱藏字元導致,也許是跟編碼有關的字元,所以由檔案讀進字串後清除這些隱藏字元,結果成功了~喔耶

$json_string = preg_replace( '/[^[:print:]]/', '',$json_string);

像這樣子

<?php
$json_string = file_get_contents('json_string.txt');
$json_string = preg_replace( '/[^[:print:]]/', '',$json_string);
$obj = json_decode( $json_string , true );
print_r($obj);
exit;
?>


範例檔案下載
download
[……]

閱讀更多

Drop and drag

Drag and drop so simple it hurts
https://github.com/bevacqua/dragula

angular-drag-and-drop-lists
http://marceljuenemann.github.io/angular-drag-and-drop-lists/

GRIDSTACK.JS
http://troolee.github.io/gridstack.js/[……]

閱讀更多

網頁前端 framework 整理

Bootstrap 4 alphahttp://blog.getbootstrap.com/2015/12/08/bootstrap-4-alpha-2/

bootstrap 3 v3.3.7
http://getbootstrap.com/

bootstrap 3 v3.3.1 (中文)
https://kkbruce.tw/bs3/

Foundation for Sites 6
http://foundation.zurb.com/

Google Material design

Polymer Paper Elements Paper elements
https://elements.polymer-project.org/

[……]

閱讀更多