關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • 5 個常見 PHP 連接資料庫問題

    Posted on August 2nd, 2006 Sam Tang No comments

    IBM developerworks 的文章,列出 5 個 PHP 連接資料庫的問題,而這些問題不是較切階的資料庫權限等,而是設計上的問題,分別有:

    Problem 1: Using MySQL directly
    直接呼叫 MySQL 函式,建議使用 PEAR DB module 或 PHP Data Objects (PDO) classes,因為當轉換資料庫系統時所修改的程式碼較少。

    Problem 2: Not using auto-increment functionality
    這個我不明白為何會有人不用 auto-increment,而是在每次插入資料時先 select 最大的 id 值,然後再加一。

    Problem 3: Using multiple databases
    初學者常見的問題,除了十分大型的系統外,根本不再兩個資料庫,但開發大型系統的開發者不會不明白這點。

    Problem 4: Not using relations
    沒有使用關聯資料庫的關聯性,即要向每個資料表發出個別 SQL 語句。當然程式也可以執行,但維護上較困難,而且執行上效能較差。

    Problem 5: The n+1 pattern
    也是效能上的問題,可以用一句 SQL 語句完成的話,比發送多個 SQL 語句為佳。

    以上是大概的內容,建議看一看原文: Five common PHP database problems


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word