技術情報
- 2021年01月25日
- 技術情報
SQL Joins
Today I would like to talk about MySQL joins along with some practical example queries.
Inner Join
2テーブルの中で同じレコードだけ出る。
(return only matching records from both tables)
Left Join
left テーブルは全レコードが出る、right テーブルのは同じレコードだけ
(return all records from the left table, and only the matched records from the right table)
Right Join
right テーブルは全レコードが出る、leftテーブルのは同じレコードだけ
(return all records from the right table, and only the matched records from the left table)
Full Outer Join
同じレコードが有る時全部レコードが出る。
(return all records from both tables if there is match record between them)
Inner Join Query Example
SELECT column(s)
FROM tb1
INNER JOIN tb2
ON tb1.column = tb2.column;
Left Join Query Example
SELECT column(s)
FROM tb1
LEFT JOIN tb2
ON tb1.column = tb2.column;
Right Join Query Example
SELECT column(s)
FROM tb1
RIGHT JOIN tb2
ON tb1.column = tb2.column;
Full Outer Join Query Example
mysql doesn’t support full join syntax directly so we can use this as an alternative.
(full join = left + right join)
SELECT column(s)
FROM tb1
LEFT JOIN tb2 ON tb1.column = tb2.column;
LEFT JOIN tb3 ON tb1.column = tb3.column;
UNION
SELECT column(s)
FROM tb1
SELECT column(s)
FROM tb1
RIGHT JOIN tb2 ON tb1.column = tb2.column;
RIGHT JOIN tb3 ON tb1.column = tb3.column;
yuuma at 2021年01月25日 04:22:16
- 2021年01月18日
- 技術情報
Calculation of time elapsed in PHP
Today I would like to write some code about calculating time elapsed in PHP. Especially if we want to know the elapsed time of inserted records (seconds, minutes, hours , days etc).
For example – Posted 1 週前、3 時間前、50 分間前、30秒間前。
Here is our function to calculate the time eclipse
<?php
function time_elapsed($datetime) {
$now = new DateTime;
$ago = new DateTime($datetime);
//getting the time differences.
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7); //week
$diff->d -= $diff->w * 7; //day
//string arrays of formats
$string = array(
'y' => '年',
'm' => '月',
'w' => '週',
'd' => '日',
'h' => '時間',
'i' => '分',
's' => '秒',
);
//mapping the time difference and format
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v;
} else {
unset($string[$k]);
}
}
//only getting the first array key and value
$string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . '前' : 'ちょうど今';
}
I have included the comments in code so that you can be able to understand it. Let’s call our function to test.
echo time_elapsed("2020-12-06 11:24:25"); //output 1 月前
echo time_elapsed(date("Y-m-d H:i:s")); //output ちょうど今
PS. we have to care about our server timezone when we are dealing with Datetime functions
By Yuuma
yuuma at 2021年01月18日 04:56:29
- 2021年01月12日
- 技術情報
Using controller function directly in Laravel blade
Today I would like to talk about using the function from controller directly on your blade view files.
Normally we wrote codes relating with application logic and database and then pass the data to specific view files. But what if we like to use the function from controller directly ?
We can create a static function in controller and then can directly be called from blade file without instantiating the class. Let me write a sample example.
Firstly, we will create a static function in controller. Why static function ?
If we create a normal function, we will need to instantiate the class in view file like this `new Controller()` which will be a mess in view files. Static function can be directly called using scope resolution (::) operator.
<?php
namespace App\Http\Controllers;
class HomeController extends Controller
{
public static function greet()
{
return "Hello World";
}
}
After that we can call the above controller function directly by providing the namespace of the controller and function using scope resolution operator like this.
<p>
{{ App\Http\Controllers\HomeController::greet() }}
<!-- output - Hello World -->
</p>
By Yuuma
yuuma at 2021年01月12日 10:00:59
- 2020年12月28日
- 技術情報
Wappalyzer technology profiler
I introduced an extension called daily.dev to read the development related articles. I will introduce more browser extension that are extremely useful next time. Also today I would like to introduce an extension called wappalyzer
Wappalyzer is a technology profiler that shows you what websites are built with.
Further more, it discovers more than a thousand technologies in dozens of categories such as programming languages, analytics, marketing tools, payment processors, CRM, CDN and others.
Go ahead this link and install the extension.
Lets take a look at yahoo website, https://www.yahoo.co.jp/
We can see the technologies we are using through the wapplyzer extension like this.

Lets take a look at another site medium.com, and lets see what technologies they are using.

Conclusion, this is a very useful plugin to trace technologies in a website such an easy way.
By Yuuma.
yuuma at 2020年12月28日 11:00:01
- 2020年12月25日
- 技術情報
[PHP] アップロード可能な最大ファイルサイズを調整する
データベースの復元処理など、ダンプファイルの容量がアップロード可能な最大ファイルサイズの初期設定(2MB)を超えている場合があります。
今回はそのような場合の対処方法を3パターン紹介します。
nishida at 2020年12月25日 10:00:13