blog's People
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
表单提交中的 x-www-form-urlencoded 和 multipart/form-data
如果開放某個 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';
CORS
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?
如果 concurrent 執行時,pdo 的 lastInsertId 是否會拿到正確的 id 呢?
答案是會,意思是不會拿到別人的 insert id。
參考解答:
Reliable or not PDO lastInsertId() when using transactions
如何顯示使用者在 mysql 裡對 database 具有哪些權限?
- 當前登入的使用者:
- SHOW GRANTS;
- SHOW GRANTS FOR CURRENT_USER;
- SHOW GRANTS FOR CURRENT_USER();
- 非當前登入的使用者:
- SHOW GRANTS FOR ''@'localhost';
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.