[Error Log] Empty AJAX responseText + parseError from JSON (MariaDB vs. mySQL)


Hell! I have been struggling on this problem for more than 2 months, and finally got an answer, and that’s related to MariaDB and mySQL. At this stage, I am still confused with whether this is the FINAL and REAL answer.

I am recording the whole process of bug discovery below here, but in a nutshell:

  1. Got empty empty responseText from jQuery AJAX call
  2. Got the parseError from the JQuery AJAX call
  3. Found the source of the error, which is caused by the json_encode function in PHP
  4. Compared the var_dump of the variable being json_encode from mySQL and MariaDB, the output is different
  5. Output frommySQL one has strange character (ASCII code 130), whileMariaDB does not
    • Remind me that mySQL allows the PHP to read and write emoticon from and into the database
    • But, MariaDB does not
    • In conclusion for now, mySQL supports I/O of more unicode characters than MariaDB does (but Asian characters are also supported)
  6. After removing the strange characters from themySQL database, problem solved.
    • Reason is due to the fact that json_encode supports only UTF-8
All string data must be UTF-8 encoded.

Nginx, Apache 設置 Laravel Routing


最近在搞一個小項目,由於小弟的 Server-side programming 的技術不高,而且要在安全性+程式碼的可讀性(自己寫完後看不懂 lol )上的考慮,就在網上找了一大堆 PHP Framework (原本考慮過不用 PHP的,想嘗試用年輕許多的 Node.JS,但受到之前的【Max-call-stack-size】跟【Memory Leakage】這些Bug 的心裡陰影,還是在自己的小項目做好了)。

比較過不同的 PHP Framework, 例如是Zend Framework、Cake PHP,還是要嘗試投進 Laravel Framework (回不了頭的選擇 :l)。為了更快的開始研究,就選擇了一個Starter Kit 來著手研究—— 來至 Snipe的  “snipe/laravel4-starter"

初始的網頁界面
初始的網頁界面

設定過程——如果已經有laravel Frame 可以使用,可以直接略過

設定的過程可以說是無痛的,因為網上都有很多的文章可以參考。

  1. 【Git Clone】: 把 Snipe的  “snipe/laravel4-starter" Clone 到自己的開發環境,留意Server 的 Document Root 有沒有設定正確
  2. 【設定 Starter-kit】: 如果你是用這個Starter-kit 才需要做這個步驟。看ReadMe 檔: https://github.com/snipe/laravel4-starter/blob/master/readme.md
  3. 【修改public Folder】: 如果你不是整個Server 都是由Laravel Frame 搭建的,建議把 laravel4-starter/public 檔案夾裡的文件都移動出來。
  4. 然後就到了這教學的重點—— Routing: 因為Server 的Setup 沒有預設到可以Route 的

閱讀更多»

[ERROR LOG] 經典錯誤 “php is not recognised as an internal or external command"


錯誤碼

  • 系統不能辨認 >>php 這段指令
  • (e.g.) 用 cmd 輸入 “php –version",但  cmd 回應這段錯誤:

php is not recognised as an internal or external command

錯誤成因

  1. 檔案不存在——那就自己下載一個吧,沒有安裝包,把下載了的壓縮檔解壓到一個地方吧
  2. PATH 設定有誤——
    • 地址有誤,打開 【Control Panel\System and Security\System > Advanced System Settings > Environment Variables > System > PATH】,然後看看有沒有 php 檔案夾的地址。沒有的話自行加上吧
    • 檔案夾的名稱有複雜的子元 (e.g. php5.5.15),把名稱改成簡單一點的吧 (e.g. php),然後更新【PATH 變數】+【php.ini 的 extentions 地址,因為 檔案夾 的名稱改變了】
php.ini 沒有更新,導致【Extension not found】

閱讀更多

  1. 文章內容來源: http://chat.stackoverflow.com/rooms/22218/discussion-between-user1049769-and-vahid-farahmand

SHTML && Javascript (AJAX) && PHP


SHTML——這看起來很古老的 (Apache 1.3 的官方Tutorial 已經收錄了,應該很有歷史吧),個人認為就是AJAX 的前身。根據維基百科的定義

Server Side Includes (SSI) is a simple interpreted server-side scripting language used almost exclusively for the Web.

The most frequent use of SSI is to include the contents of one or more files into a web page on a web server.

SSI 就是為網頁提供非常基本的 Server 跟 Client 的 Interaction。

(Oreilly)
(Oreilly)

一句話定義

就是 Server 在傳送 網頁 到 Client Side 前,先把 shtml 的相關Script 編譯、把結果加到網頁,然後整張網頁內容輸出。

把時間印到網頁上

  1. 如果看的網頁是 html——用AJAX的方式,從 Client 的瀏覽器召喚一段 CGI 的程序,然後從 Server 傳送回 Client。比如說要 Server 的現在時間,就可用以下 PHP Code:
    <?php
        ...
        $now = new DateTime();
        echo $now->format('Y-m-d H:i:s');
    ?>

    然後在Client 的瀏覽器,用Javascipt 收取現在的時間資料,再編譯到網頁上。

  2. 如果直接用 php 網頁——直接就 echo 出去了。
  3. 如果用SHTML——
    (HTML Comment Begin)#config timefmt="%A %B %d, %Y" (HTML Comment End)
    
    Today is(HTML Comment Begin)#echo var="DATE_LOCAL" (HTML Comment End)
    

這樣的代碼,在 Server 的運作過程是這樣的: Server 先讀取 .shtml 這檔案 –> 解讀 “ 融合到 .shtml –> 傳給 Client 的瀏覽器

把通用的網頁合併到不同的網頁 (e.g. header, footer, navbar)

個人認為這個作用比較大,但對於 Server-side 和 Client-side 的負載 vs. 把 header 的 code 放到所有網頁,所以實際應用還是不大。

用一下 shtml 代碼解釋一下:

<!--#include virtual="/footer.html" -->
<!--#include file="/header.html" -->

(用 “virtual" 或者 “file" 效果都是一樣的,但 “virtual"  的可以用 absolute path,而 “file" 不可以)

  1. 跟Javascript 比較——
    • (v) 沒有開啟 Javascript 的瀏覽器都可以編譯內容,雖然現在所有瀏覽器都有開啟 javascript
    • (x) 一旦載入了網頁,如果要變更內容,還是需要 javascript
    • (~) 倒不如直接把 header, footer 的代碼寫入網頁
  2. 跟php 比較——
    • (x) 雖然 Server 要編譯的代碼很少,不需要 “echo",但相對 php,Server workload 應該沒分別的

初步探究,還是用回 javascript/ cgi 算了~

跟 Javascript || PHP 相比,shtml 實在是太陽春了,畢竟當年還未有成熟的 AJAX 技術,所以在當時可能就會用到,但現在已經銷聲匿跡了(很多網頁還有 .shtml 的網頁,但相關的教學極其稀有)。

閱讀更多

  1. Apache Tutorial: Introduction to Server Side Includes
  2. Washington University – An SHTML sample
  3. SSI-Developer.net – SSI Tutorials, Server Side Includes