본문 바로가기

카테고리 없음

php pdo wrapper Medoo

반응형

Medoo - The lightweight PHP database framework to accelerate development.

 

Medoo - The lightweight PHP database framework to accelerate development

Compatible Works with MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, Oracle, Sybase, and more. Friendly Integrates seamlessly with Laravel, CodeIgniter, Yii, Slim, and other PHP frameworks.

medoo.in

 

PHP 경량 데이터 프레임워크라고 설명하고 있다.

 

pdo를 감싼 라이브러리로 보이며,

 

생각보다 간편하지만 강력한 기능을 보여준다.

 

단점은 php의 named parameter를 지원하지는 않는다.는 점과

 

Join 파라미터 사용버과 where 컨디션 사용법이 생각보다는 눈에 익지 않을 수 있다는 것이다.

 

공식문서에 있는 몇가지 예제를 첨부한다

 

Where 조건 사용법(공식 문서)

$database->select("account", "user_name", [
	"email" => "foo@bar.com"
]);
// WHERE email = 'foo@bar.com'
 
$database->select("account", "user_name", [
	"user_id" => 200
]);
// WHERE user_id = 200
 
$database->select("account", "user_name", [
	"user_id[>]" => 200
]);
// WHERE user_id > 200
 
$database->select("account", "user_name", [
	"user_id[>=]" => 200
]);
// WHERE user_id >= 200
 
$database->select("account", "user_name", [
	"user_id[!]" => 200
]);
// WHERE user_id != 200
 
$database->select("account", "user_name", [
	"age[<>]" => [200, 500]
]);
// WHERE age BETWEEN 200 AND 500
 
$database->select("account", "user_name", [
	"age[><]" => [200, 500]
]);
// WHERE age NOT BETWEEN 200 AND 500

 

 

And 조건 사용법

$database->select("account", "user_name", [
	"AND" => [
		"user_id[>]" => 200,
		"age[<>]" => [18, 25],
		"gender" => "female"
	]
]);
 
// Medoo will connect the relativity condition with AND by default. The following usage is the same as above.
$database->select("account", "user_name", [
	"user_id[>]" => 200,
	"age[<>]" => [18, 25],
	"gender" => "female"
]);

 

 

OR 사용법

$database->select("account", "user_name", [
	"OR" => [
		"user_id[>]" => 200,
		"age[<>]" => [18, 25],
		"gender" => "female"
	]
]);

 

 

And와 OR 같이 사용

$database->has("account", [
	"AND" => [
		"OR" => [
			"user_name" => "foo",
			"email" => "foo@bar.com"
		],
		"password" => "12345"
	]
]);

 

 

 

테이블 조인

  • [>] ==> LEFT JOIN
  • [<] ==> RIGHT JOIN
  • [<>] ==> FULL JOIN
  • [><] ==> INNER JOIN
$database->select("post", [
	// Here is the table relativity argument that tells the relativity between the table you want to join.
	"[>]account" => ["author_id" => "user_id"]
], [
	"post.title",
	"account.city"
]);

 

 

Table alias

"[>]account (replier)" => ["replier_id" => "user_id"]

=>LEFT JOIN "account" AS "replier" ON "post"."replier_id" = "replier"."user_id"

 

 

장점

- 다소 복잡한 쿼리를 간단히 사용 할 수 있다.

- 데이터 타입지정이나 구조 정의가 쉬움

 

단점

- 조인 키워드나 alias 지정등이 sql과 좀 달라 학습곡선이 필요함

- ai 피셜) 지나치게 복잡한 쿼리엔 적합하지 않음

반응형