Medoo 마이크로 프레임의 디테일 구덩이

9006 단어 일상 개발

1. insert() 반환값


결론: insert (), 업데이트 (), delete () 세 함수는 pdo 대상을 되돌려줍니다.
Medoo 1.4.5 마이크로 프레임을 사용할 때 중국어 문서에 따라 $database->insert() 함수를 호출할 때 반환 값은 다음과 같습니다.Return: [number] id
이 반환은 1.2의 구 버전과 일치하는 것 같지만 실제 반환 값은 id가 아닙니다.
PDOStatement 객체
, 설명서 아래에 설명되어 있습니다.
PDOStatement insert () 는 PDOStatement 대상을 되돌려줍니다. 더 많은 정보를 얻을 수 있습니다.
$data = $database->insert("account", [
    "user_name" => "foo",
    "email" => "[email protected]",
    "age" => 25
]);
// Returns the number of rows affected by the last SQL statement
echo $data->rowCount();
// Read more: http://php.net/manual/en/class.pdostatement.php

중국어 문서 주소:http://medoo.lvtao.net/1.2/doc.insert.php
메도오 홈페이지에 들어가면 새 문서의 첫 페이지에 새 버전이 구 버전과 다르다는 것을 뚜렷하게 알 수 있다. 그 중에서 insert(),update(),delete() 세 함수는 모두 pdo 대상을 되돌려준다.
Update, Insert And Delete Return Result update(), insert() and delete() method will return the PDO::Statement object instead of number of affected row since 1.4. You can call its method for more special usage.
공식 영문 문서와 비교하여 $database->insert() 함수를 호출할 때 반환 값은 다음과 같습니다.Return: [PDOStatement] The PDOStatement object.
삽입된 id를 얻으려면 medoo 대상의 id() 함수를 호출해야 합니다.
For old version, the API insert() will return the last inserted row ID by default. But for Medoo 1.2, you have to call the new API id() alone to get the ID.
$database->insert("account", [
    "user_name" => "foo",
    "email" => "[email protected]",
    "age" => 25
]);

// id
$account_id = $database->id();
$pdo = $database->insert("account", [
    "user_name" => "foo",
    "email" => "[email protected]",
    "age" => 25
]);

 // 
$effectedRow = $pdo->rowCount()
// id
$insert_id = $database->id();

이것은 중국어 문서를 번역할 때 소홀히 한 것이 매우 명백하니 참고 문서는 가능한 한 영문 원판을 찾아라.

2. get() 반환값


결론: 필드 파라미터가 직접string으로 채워지면 필드 값을 직접 되돌려줍니다.필드 매개 변수가 수조로 채워지면 관련 수조로 되돌아옵니다
Medoo 1.4.5 마이크로 프레임 문서에 따라 $database->get() 반환 값은
Return: [string/array/int/object]
Return the data of the column.
get()의 반환 값은 필드 매개 변수에 따라 조정됩니다.
필드 매개 변수를 직접 입력하면, 되돌아오는 결과 형식은 테이블에 있는 필드의 유형에 따라 결정됩니다.예를 들면 다음과 같습니다.
// 
$email = $database->get("account", "email", [
    "user_id" => 1234
]);
// $email = "[email protected]"  
//  : string


$point= $database->get("account", "point", [
    "user_id" => 1234
]);
// $point= 100  
//  : int
[' 1',' 2']로 1개 이상의 매개 변수를 기입하면 되돌아오는 결과는 수조입니다.특히 주의해야 할 것은 중괄호 형식으로 파라미터를 기입하면 한 파라미터만 기입해도 수조로 되돌아온다는 것이다.예를 들면 다음과 같습니다.
//   
$data = $database->get("account", [
    "email"
], [
    "user_id" => 1234
]);
// $data = array("email"=> "[email protected]"); 
//  : array

//   
$profile = $database->get("account", [
    "email",
    "gender",
    "location"
], [
    "user_id" => 1234
]); 
// $profile = array(
//  "email" => "[email protected]",
//  "gender" => "female",
//  "location" => "earth"
// );

3. 별명 질문


만약 테이블에 별명을 지정하고 두 테이블에 중복된 필드 이름이 존재한다면, 테이블을 연결할 때 반드시 별명 접두사를 붙여야 한다.

$data = $database->select($table.'(p)',// 
            [
                "[>]$table_h(h)" => [
                    "p.id" => "pid"
                    /**  ,join 
                     *   , 
                     *  p h id 
                     *    
                     *  "id" => "pid" 
                     *   "p.id"=>"h.id"  
                    **/
                ]
            ],
            [
                'p.id',
                'p.title_text',
                'p.title_pic',
                'p.answers',
                'p.language',
                'p.classification',
                'p.pro_type',
                'p.pro_source',
                'h.hint'
                // , , 

            ], [
                'AND' => [
                    'p.id' => $pid,
                    'p.visible[!]' => 0
                ]
            ]);

참고 자료


Medoo 중국어 사이트:[유행이 지났음]http://medoo.lvtao.net/
Medoo 영문 공식 사이트:https://medoo.in/

좋은 웹페이지 즐겨찾기