Câu hỏi pv php + mysql
PHP
1) What will be the output of those code?
var_dump(0123 == 123); var_dump('0123' == 123); var_dump('0123' === 123);
2) Multiple inheritance là gì? PHP có support ko?
class A extends class B, class C
PHP ko support.
3) trait php là gì
4) yield
5)
How can I measure the speed of code written in PHP
$before = microtime(true);
for ($i=0 ; $i<100000 ; $i++) {
serialize($list);
}
$after = microtime(true);
echo ($after-$before)/$i . " sec/serialize\n";
7) How to check how much memory your PHP scripts usememory_get_usage8) what is difference between:
$resp = json_decode(file_get_contents($url), TRUE);
$resp = json_decode(@file_get_contents($url), TRUE);
-> php suppression error (error control operator)
9) Trong Laravel xem log ở đâu, đã từng dùng third party nào để check log?
10) khai báo shallow() trong route.
Shallow Nesting Route?
https://laravel.com/docs/8.x/controllers#shallow-nesting
11)
authenticate with OAuth providers using Laravel Socialite. Socialite currently supports authentication with Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket.
--> Laravel Socialite
12)
$user = User::find(1); $user->touch();
touch() này để làm gì?
13)
class Comment extends Model {
protected $touches = ['post'];// --> what does this mean
public function post()
{
return $this->belongsTo('Post');
}
}$comment = Comment::find(1); $comment->text = 'Edit to this comment!'; $comment->save();
https://laraveldaily.com/eloquent-touch-for-models-and-their-relationships/
14) Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean?
With
with() is for eager loading. That basically means, along the main model, Laravel will preload the relationship(s) you specify. With đi kèm với khái niệm eager loading, tức là đi kèm với main model, Laravel sẽ load thêm dữ liệu của model có quan hệ với model chính. Ví dụ
User > hasMany > Post
$users = User::with('posts')->get();
foreach($users as $user){
$users->post; // posts is already loaded and no additional DB query is run
}
Has
If you just use has('relation') that means you only want to get the models that have at least one related model in this relation. --> là 1 dạng filter (sử dụng where), khi muốn lấy các model chính có ít nhất 1 model con
User > hasMany > Post
$users = User::has('posts')->get();
// only users that have at least one post are contained in the collection
WhereHas
whereHas() works basically the same as has() but allows you to specify additional filters for the related model to check. --> giống như has nhưng thêm điều kiện filter
Example:
User > hasMany > Post
$users = User::whereHas('posts', function($q){
$q->where('created_at', '>=', '2015-01-01 00:00:00');
15 - Laravel query builder conditional-clauses
https://laravel.com/docs/8.x/queries#conditional-clauses
16 - Notifiable trait in laravel
})->get();
// only users that have posts from 2015 on forward are returned
Microservices
1 - API là gì?
2 - CORS error?
3 - Options, preflight request
4- CQRS pattern
Mysql
- có 1 bảng là table_old, giờ muốn tao 1 bảng là table_new có cấu trúc và dữ liệu giống hệt table_old, làm ntn?
CREATE TABLE table_new LIKE table_old;
INSERT INTO table_new SELECT * FROM table_old
- Ví dụ có bảng customer, trong đó chúng ta muốn lưu dữ liệu metadata dạng json trong cột `data`
{
"field_1": "value 1"
}
câu query dưới đây sẽ lấy ra tất cả dữ liệu với field_1 = value 1
SELECT * FROM customer WHERE JSON_EXTRACT(data, "$.field_1") = "value 1";
- Storage engine in Mysql ?
InnoDB ? -> lock row
MyIsam? -> lock table
- What happen when 2 or more than 2 process manipulate on the same row of MySQL DB
--> deadlock when trying to get lock
- Too Many connections error
- SHOW FULL PROCESSLIST; dùng để làm gì
- Fuzzy Search
Tìm chuỗi gần giống nhất với search input.
Ví dụ có cột là name gồm
Jon
John
Jones
Jonny
Mary
,,.
người dùng input Jon, tìm những record match với input và sắp xếp theo độ chính xác (closest match)
- GROUP_CONCAT
hiển thị dữ liệu ở 1 cột dưới dạng cách nhau = dấu , thay vì hiển thị nhiều row khi join
age| name
++++++++
1 | alex
1 | adam
1 | adnan
2 | ben
2 | bush
3 | cris
4 | daisi
4 | diana
And I'd like to make a new table like this:
age | name
+++++++++++
1 | alex, adam, adnan
2 | ben, bush
3 | cris
4 | daisi, diana
https://lucidar.me/en/web-dev/levenshtein-distance-in-mysql/
Unit Test
1-pestphp

Comments
Post a Comment