Git Product home page Git Product logo

blog's People

Contributors

hrh47 avatar

Watchers

 avatar  avatar

blog's Issues

如何更改 mysql 預設的字元編碼?

更改 /etc/mysql/my.cnf,增加這些設定:

[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

如果開放某個 database 的權限給某個使用者?

  • GRANT ALL PRIVILEGES ON database.table TO 'user'@'localhost';
  • 某個 database 底下的所有 table:
    GRANT ALL PRIVILEGES ON database.* TO 'user'@'localhost';
  • 所有 database 下的所有 table:
    GRANT ALL PRIVILEGES ON . TO 'user'@'localhost';

mysql 如何執行 sql 檔

  • shell 底下:
    mysql db_name < file_name;
    如果 file 有 use db_name; 的話:
    mysql < file_name
  • mysql client 裡:
    source file_name;
    或 . file_name;

ORM 的 pattern

有 Active Record Pattern 和 Data Mapper Pattern 兩種

兩者的差別在哪呢?先看看 code:

# Active Record Pattern
$user = new User;
$user->username = 'andrew';
$user->save();

# Data Mapper Pattern
$user = new User;
$user->username = 'andrew';
EntityManager::persist($user);

意思是說 Active Record 式的 ORM 會直接將 model object 對應到 database 裡的 row,而 Data Mapper 式的 ORM 則是透過 Entity Manager 來把 object 儲存到 database。

因為作法上的不同,Active Record 式的 ORM 的 Model 都需要繼承一個 base Active Record Object,所以會比較肥大,而 Data Mapper 式的 ORM 把處理資料和儲存兩部份切開,所以比較輕量。

什麼時候該用 Active Record Pattern 什麼時候該用 Data Mapper Pattern?

如果在做簡易 CRUD 的 application 比較適合用 Active Record Pattern ORM,商業邏輯較複雜的應用則比較適合用 Data Mapper Pattern 的 ORM。

參考資料:
What's the difference between Active Record and Data Mapper?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.