What are the technical reasons for why one shouldn’t use 사용해서는 안 되는 기술적 이유는 무엇입니까?mysql_*
functions?기능하고 있습니까? (e.g. (예:mysql_query()
, ,mysql_connect()
or 또는mysql_real_escape_string()
)?)?
Why should I use something else even if they work on my site?내 사이트에서 작동하는데 다른 것을 사용해야 하는 이유는 무엇입니까?
If they don’t work on my site, why do I get errors like 내 사이트에서 작동하지 않는 경우 다음과 같은 오류가 발생하는 이유는 무엇입니까?
Warning: mysql_connect(): No such file or directory경고: mysql_connect(): 해당 파일 또는 디렉토리가 없습니다.
질문에 대한 답변
The MySQL extension:MySQL 확장자:
- Is not under active development현재 개발 중이 아님
- Is officially deprecated as of PHP 5.5 (released June 2013).PHP 5.5(2013년 6월 출시)를 기점으로 공식적으로 폐지되었습니다.
- Has been removed entirely as of PHP 7.0 (released December 2015) PHP 7.0(2015년 12월 출시)에서 완전히 삭제되었습니다.
- This means that as of 31 Dec 2018 it does not exist in any supported version of PHP.즉, 2018년 12월 31일 현재 지원되는 버전의 PHP에는 존재하지 않습니다. If you are using a version of PHP which supports it, you are using a version which doesn’t get security problems fixed.이를 지원하는 PHP 버전을 사용하는 경우 보안 문제가 해결되지 않은 버전을 사용하는 것입니다.
- Lacks an OO interfaceOO 인터페이스가 없음
- Doesn’t support: 지원하지 않음:
- Non-blocking, asynchronous queries비블로킹, 비동기 쿼리
- Prepared statements or parameterized queries준비된 문 또는 매개 변수화된 쿼리
- Stored procedures저장 프로시저
- Multiple Statements복수 스테이트먼트
- Transactions트랜잭션
- The “new” password authentication method (on by default in MySQL 5.6; required in 5.7)“새로운” 비밀번호 인증 방식(MySQL 5.6에서는 기본 설정, 5.7에서는 필수)
- Any of the new functionality in MySQL 5.1 or laterMySQL 5.1 이후 신기능 중 하나
Since it is deprecated, using it makes your code less future proof.더 이상 사용되지 않기 때문에 이 기능을 사용하면 향후 코드 증명에 도움이 되지 않습니다.
Lack of support for prepared statements is particularly important as they provide a clearer, less error-prone method of escaping and quoting external data than manually escaping it with a separate function call.준비된 스테이트먼트를 지원하지 않는 것이 특히 중요합니다.이것은, 다른 함수 호출에 의해서 수동으로 데이터를 이스케이프 하는 것보다, 외부 데이터를 이스케이프 해 견적하는, 보다 명확하고 에러가 발생하기 쉬운 방법을 제공하기 때문입니다.
See the comparison of SQL extensions.SQL 확장의 비교를 참조하십시오.
PHP offers three different APIs to connect to MySQL.PHP는 MySQL에 접속하기 위한 3가지 API를 제공합니다. These are the mysql
(removed as of PHP 7), mysqli
, and PDO
extensions.(PHP 7에서 삭제됨), 및 확장입니다.
The 그mysql_*
functions used to be very popular, but their use is not encouraged anymore.예전에는 매우 인기가 많았지만, 이제는 그 사용이 권장되지 않습니다. The documentation team is discussing the database security situation, and educating users to move away from the commonly used ext/mysql extension is part of this (check php.internals: deprecating ext/mysql).문서 팀은 데이터베이스 보안 상황에 대해 논의하고 있으며, 일반적으로 사용되는 ext/mysql 확장자에서 벗어나도록 사용자를 교육하는 것도 그 일부입니다(ph.internals: decreating ext/mysql).
And the later PHP developer team has taken the decision to generate E_DEPRECATED
errors when users connect to MySQL, whether through 그리고 나중에 나온 PHP 개발자 팀은 사용자가 MySQL에 접속할 때 오류를 발생시키기로 결정했습니다.mysql_connect()
, ,mysql_pconnect()
or the implicit connection functionality built into 또는 암묵적인 접속기능이 내장되어 있습니다.ext/mysql
..
ext/mysql
was officially deprecated as of PHP 5.5 and has been removed as of PHP 7.ext/mysql
PHP 5.5에서 공식적으로 폐지되었으며 PHP 7에서 제거되었습니다.
See the Red Box?빨간 상자 보여?
When you go on any 어떤 일을 할 때mysql_*
function manual page, you see a red box, explaining it should not be used anymore.기능 매뉴얼 페이지에 빨간색 상자가 표시되어 더 이상 사용하지 않아야 함을 설명합니다.
Why왜죠
Moving away from 에서 벗어나다ext/mysql
is not only about security, but also about having access to all the features of the MySQL database.보안뿐만 아니라 MySQL 데이터베이스의 모든 기능에 액세스할 수 있어야 합니다.
ext/mysql
was built for MySQL 3.23 and only got very few additions since then while mostly keeping compatibility with this old version which makes the code a bit harder to maintain.MySQL 3.23용으로 구축되어 그 이후 거의 추가되지 않았지만 대부분 이전 버전과의 호환성을 유지하고 있어 코드를 유지하기가 다소 어렵습니다. Missing features that is not supported by 에서 지원되지 않는 기능 누락ext/mysql
include: (from PHP manual).include: (PHP 매뉴얼 참조)
- Stored procedures (can’t handle multiple result sets)저장 프로시저(복수의 결과 세트를 처리할 수 없음)
- Prepared statements준비된 스테이트먼트
- Encryption (SSL)암호화(SSL)
- Compression압축
- Full Charset support풀 문자 집합 지원
Reason to not use mysql_*
function:기능을 사용하지 않는 이유:
- Not under active development현재 개발 중이 아님
- Removed as of PHP 7PHP 7에서 삭제됨
- Lacks an OO interfaceOO 인터페이스가 없음
- Doesn’t support non-blocking, asynchronous queries비차단 비동기 쿼리를 지원하지 않습니다.
- Doesn’t support prepared statements or parameterized queries준비된 문 또는 매개 변수화된 쿼리를 지원하지 않습니다.
- Doesn’t support stored procedures저장 프로시저를 지원하지 않습니다.
- Doesn’t support multiple statements여러 문을 지원하지 않습니다.
- Doesn’t support transactions트랜잭션을 지원하지 않습니다.
- Doesn’t support all of the functionality in MySQL 5.1MySQL 5.1의 일부 기능을 지원하지 않음
Above point quoted from Quentin’s answer쿠엔틴의 답변에서 인용한 상기 사항
Lack of support for prepared statements is particularly important as they provide a clearer, less error prone method of escaping and quoting external data than manually escaping it with a separate function call.준비된 스테이트먼트를 지원하지 않는 것이 특히 중요합니다.이는 다른 함수 호출을 사용하여 수동으로 데이터를 이스케이프하는 것보다 더 명확하고 오류가 발생하기 쉬운 외부 데이터 이스케이프 방법을 제공하기 때문입니다.
See the comparison of SQL extensions.SQL 확장의 비교를 참조하십시오.
Suppressing deprecation warnings폐지 경고 억제
While code is being converted to 코드 변환 중MySQLi
//PDO
, ,E_DEPRECATED
errors can be suppressed by setting 에러는, 설정함으로써 억제할 수 있습니다.error_reporting
in php.ini to exclude 제외할 php.ini 내E_DEPRECATED:
error_reporting = E_ALL ^ E_DEPRECATED
Note that this will also hide other deprecation warnings, which, however, may be for things other than MySQL. (from PHP manual)이것은 다른 권장 해제 경고도 숨겨지지만 MySQL 이외의 경고일 수 있습니다.(PHP 매뉴얼 참조)
The article PDO vs.PDO와 MySQLi: Which Should You Use? by Dejan Marjanovic will help you to choose. Dejan Marjanovic의 MySQLi: Which Should You Use?가 선택에 도움이 됩니다.
And a better way is 그리고 더 좋은 방법은PDO
, and I am now writing a simple , 그리고 나는 지금 간단한 글을 쓰고 있다.PDO
tutorial.튜토리얼을 참조해 주세요.
A simple and short PDO tutorial간단하고 짧은 PDO 튜토리얼
Q. First question in my mind was: what is `PDO`?Q. 첫 번째 의문점은 PDO가 무엇인가였다.
A. “PDO – PHP Data Objects – is a database access layer providing a uniform method of access to multiple databases.”A. “PDO – PHP Data Objects – 여러 데이터베이스에 대한 통일된 액세스 방법을 제공하는 데이터베이스 액세스 계층입니다.”
Connecting to MySQL MySQL에 연결
With 와 함께mysql_*
function or we can say it the old way (deprecated in PHP 5.5 and above)또는 이전 방식으로 말할 수 있습니다(PHP 5.5 이상에서는 권장되지 않음).
$link = mysql_connect('localhost', 'user', 'pass'); mysql_select_db('testdb', $link); mysql_set_charset('UTF-8', $link);
With 와 함께PDO
: All you need to do is create a new : 새로 작성하기만 하면 됩니다.PDO
object.물건. The constructor accepts parameters for specifying the database source 생성자가 데이터베이스 소스를 지정하기 위한 매개 변수를 수락합니다.PDO
‘s constructor mostly takes four parameters which are 의 컨스트럭터는 주로 다음 4개의 파라미터를 취합니다.DSN
(data source name) and optionally (데이터 소스 이름) 및 옵션username
, ,password
..
Here I think you are familiar with all except 여기서 당신은 모든 것에 익숙하다고 생각합니다만,DSN
; this is new in 의 새로운 기능PDO
. A .aDSN
is basically a string of options that tell 기본적으로는 일련의 옵션입니다.PDO
which driver to use, and connection details.사용할 드라이버 및 연결 세부 정보. For further reference, check PDO MySQL DSN.자세한 내용은 PDO MySQL DSN을 참조하십시오.
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
Note: you can also use 주의: 다음을 사용할 수도 있습니다.charset=UTF-8
, but sometimes it causes an error, so it’s better to use 단, 에러가 발생할 수 있으므로 를 사용하는 것이 좋습니다.utf8
..
If there is any connection error, it will throw a 접속 에러가 발생했을 경우, 이 에러는PDOException
object that can be caught to handle 잡을 수 있는 물건Exception
further.더.
Good read: Connections and Connection management 올바른 읽기: 연결 및 연결 관리
You can also pass in several driver options as an array to the fourth parameter.여러 드라이버 옵션을 배열로 네 번째 매개 변수에 전달할 수도 있습니다. I recommend passing the parameter which puts 이 매개 변수를 전달할 것을 권장합니다.PDO
into exception mode.예외 모드로 합니다. Because some 왜냐하면…PDO
drivers don’t support native prepared statements, so 드라이버는 네이티브 준비 스테이트먼트를 지원하지 않기 때문에PDO
performs emulation of the prepare.는 준비 에뮬레이션을 수행합니다. It also lets you manually enable this emulation.이 에뮬레이션을 수동으로 실행할 수도 있습니다. To use the native server-side prepared statements, you should explicitly set it 네이티브 서버 측에서 준비된 문을 사용하려면 명시적으로 설정해야 합니다.false
..
The other is to turn off prepare emulation which is enabled in the 다른 하나는 에서 활성화되어 있는 준비 에뮬레이션을 끄는 것입니다.MySQL
driver by default, but prepare emulation should be turned off to use 디폴트 드라이버입니다만, 에뮬레이션을 사용하려면 , 준비 에뮬레이션을 오프할 필요가 있습니다.PDO
safely.안전하게.
I will later explain why prepare emulation should be turned off.준비 에뮬레이션을 꺼야 하는 이유는 나중에 설명하겠습니다. To find reason please check this post.이유를 찾으려면 이 게시물을 확인하십시오.
It is only usable if you are using an old version of 이전 버전의 를 사용하고 있는 경우에만 사용할 수 있습니다.MySQL
which I do not recommended.추천하지 않습니다.
Below is an example of how you can do it:다음은 그 방법의 예입니다.
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Can we set attributes after PDO construction?PDO 시공 후 속성을 설정할 수 있습니까?
Yes, we can also set some attributes after PDO construction with the 네, PDO 구축 후 몇 가지 속성을 설정할 수도 있습니다.setAttribute
method:방법:
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Error Handling 에러 처리
Error handling is much easier in 에러 처리의 용이성은PDO
than 보다mysql_*
..
A common practice when using 사용하는 경우의 일반적인 방법mysql_*
is:다음과 같습니다.
//Connected to MySQL $result = mysql_query("SELECT * FROM table", $link) or die(mysql_error($link));
OR die()
is not a good way to handle the error since we can not handle the thing in 에러를 처리하는 방법은 적절하지 않습니다.그것은, 에러에 대처할 수 없기 때문입니다.die
. It will just end the script abruptly and then echo the error to the screen which you usually do NOT want to show to your end users, and let bloody hackers discover your schema.스크립트가 갑자기 종료되고 보통 최종 사용자에게 보여주고 싶지 않은 오류가 화면에 반영되어 빌어먹을 해커들이 스키마를 발견하게 됩니다. Alternately, the return values of 또는 의 반환값mysql_*
functions can often be used in conjunction with mysql_error() to handle errors.함수를 mysql_error()와 함께 사용하여 오류를 처리할 수 있습니다.
PDO
offers a better solution: exceptions.는 예외라는 더 나은 해결책을 제공합니다. Anything we do with 우리가 하는 모든 일PDO
should be wrapped in a 에 싸야 한다try
––catch
block. We can force 차단해, 강제로PDO
into one of three error modes by setting the error mode attribute.에러 모드 Atribute를 설정함으로써, 3개의 에러 모드 중 하나로 이행합니다. Three error handling modes are below.3가지 에러 처리 모드를 다음에 나타냅니다.
PDO::ERRMODE_SILENT
. It’s just setting error codes and acts pretty much the same as 에러 코드를 설정했을 뿐이며, 동작은 다음과 같습니다.mysql_*
where you must check each result and then look at 각 결과를 확인하고 나서$db->errorInfo();
to get the error details.에러의 상세를 취득합니다.PDO::ERRMODE_WARNING
Raise 올리다E_WARNING
. (Run-time warnings (non-fatal errors).. (실행시 경고(치명적이지 않은 오류) Execution of the script is not halted.)스크립트의 실행은 정지되지 않습니다).PDO::ERRMODE_EXCEPTION
: Throw exceptions.: 예외를 설정합니다. It represents an error raised by PDO.PDO에 의해 발생한 오류를 나타냅니다. You should not throw a 던지면 안 돼요PDOException
from your own code.당신의 코드로요. See Exceptions for more information about exceptions in PHP.PHP의 예외에 대한 자세한 내용은 예외를 참조하십시오. It acts very much like 이 동작은 마치or die(mysql_error());
, when it isn’t caught.잡히지 않을 때. But unlike 하지만 그와는 달리or die()
, the ,그PDOException
can be caught and handled gracefully if you choose to do so.를 검출하여 적절하게 처리할 수 있습니다.
Good read:좋은 읽기:
Like:예를 들어 다음과 같습니다.
$stmt->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); $stmt->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING ); $stmt->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
And you can wrap it in 그리고 당신은 그것을 포장할 수 있다.try
––catch
, like below:다음과 같습니다.
try { //Connect as appropriate as above $db->query('hi'); //Invalid query! } catch (PDOException $ex) { echo "An Error occured!"; //User friendly message/message you want to show to user some_logging_function($ex->getMessage()); }
You do not have to handle with 를 사용하여 처리할 필요가 없습니다.try
––catch
right now.지금 당장. You can catch it at any time appropriate, but I strongly recommend you to use 언제든지 적절한 시간에 잡을 수 있지만, 나는 당신이 그것을 사용하는 것을 강력히 추천한다.try
––catch
. Also it may make more sense to catch it at outside the function that calls the 또, 콜 하는 함수의 외부로부터 캐치 하는 것이, 보다 타당할 가능성이 있습니다.PDO
stuff:내용:
function data_fun($db) { $stmt = $db->query("SELECT * FROM table"); return $stmt->fetchAll(PDO::FETCH_ASSOC); } //Then later try { data_fun($db); } catch(PDOException $ex) { //Here you can handle error and show message/perform action you want. }
Also, you can handle by 또한 다음 방법으로 처리할 수 있습니다.or die()
or we can say like 혹은 이렇게 말할 수 있다.mysql_*
, but it will be really varied.하지만 정말 다양할 거예요. You can hide the dangerous error messages in production by turning 다음을 수행하여 프로덕션에서 위험한 오류 메시지를 숨길 수 있습니다.display_errors off
and just reading your error log.에러 로그를 읽고 있습니다.
Now, after reading all the things above, you are probably thinking: what the heck is that when I just want to start leaning simple 이제, 위의 모든 것을 읽고 나면, 당신은 아마 생각할 것이다: 내가 단지 단순하게 기대고 싶을 때, 대체 저게 뭐지?SELECT
, ,INSERT
, ,UPDATE
, or , 또는DELETE
statements?스테이트먼트 Don’t worry, here we go:걱정 마세요. 여기 있습니다.
Selecting Data데이터 선택
So what you are doing in 그래서 지금 하고 있는 일은mysql_*
is:다음과 같습니다.
<?php $result = mysql_query('SELECT * from table') or die(mysql_error()); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_assoc($result)) { echo $row['field1']; }
Now in 자, 들어가겠습니다.PDO
, you can do this like:다음과 같이 할 수 있습니다.
<?php $stmt = $db->query('SELECT * FROM table'); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['field1']; }
Or또는
<?php $stmt = $db->query('SELECT * FROM table'); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); //Use $results
Note: If you are using the method like below (주의: 다음과 같은 방법을 사용하는 경우(query()
), this method returns a ), 이 메서드는PDOStatement
object.물건. So if you want to fetch the result, use it like above.따라서 결과를 가져오려면 위와 같이 사용하십시오.
<?php foreach($db->query('SELECT * FROM table') as $row) { echo $row['field1']; }
In PDO Data, it is obtained via the PDO 데이터에서 이 정보는->fetch()
, a method of your statement handle.스테이트먼트 핸들링의 메서드. Before calling fetch, the best approach would be telling PDO how you’d like the data to be fetched.fetch를 호출하기 전에 가장 좋은 방법은 PDO에 데이터 가져오기 방법을 알려주는 것입니다. In the below section I am explaining this.아래 섹션에서는 이에 대해 설명합니다.
Fetch Modes가져오기 모드
Note the use of 의 사용에 주의해 주세요.PDO::FETCH_ASSOC
in the 에서fetch()
and 그리고.fetchAll()
code above.위의 코드 This tells 이것이 말해준다PDO
to return the rows as an associative array with the field names as keys.필드 이름을 키로 하여 행을 연관 배열로 반환합니다. There are many other fetch modes too which I will explain one by one.그 밖에도 여러 가지 페치모드가 있어 하나하나 설명하겠습니다.
First of all, I explain how to select fetch mode:먼저 fetch 모드를 선택하는 방법을 설명합니다.
$stmt->fetch(PDO::FETCH_ASSOC)
In the above, I have been using 위에서는, 지금까지,fetch()
. You can also use:. 다음 항목도 사용할 수 있습니다.
PDOStatement::fetchAll()
– Returns an array containing all of the result set rowsPDOStatement::fetchAll()
– 모든 결과 집합 행을 포함하는 배열을 반환합니다.PDOStatement::fetchColumn()
– Returns a single column from the next row of a result setPDOStatement::fetchColumn()
– 결과 집합의 다음 행에서 단일 열을 반환합니다.PDOStatement::fetchObject()
– Fetches the next row and returns it as an object.PDOStatement::fetchObject()
– 다음 행을 가져와 개체로 반환합니다.PDOStatement::setFetchMode()
– Set the default fetch mode for this statementPDOStatement::setFetchMode()
– 이 문의 기본 가져오기 모드를 설정합니다.
Now I come to fetch mode:이제 가져오기 모드로 들어갑니다.
PDO::FETCH_ASSOC
: returns an array indexed by column name as returned in your result set: 결과 세트에 반환된 대로 열 이름으로 인덱스된 어레이를 반환합니다.PDO::FETCH_BOTH
(default): returns an array indexed by both column name and 0-indexed column number as returned in your result set(기본값): 결과 집합에 반환된 대로 열 이름과 0-숫자 열 번호로 인덱싱된 배열이 반환됩니다.
There are even more choices!더 많은 선택지가 있다! Read about them all in PDOStatement
Fetch documentation..Fetch 설명서에서 이러한 모든 내용을 읽어보십시오.
Getting the row count:행 개수 가져오기:
Instead of using 사용하는 대신mysql_num_rows
to get the number of returned rows, you can get a 반환된 행의 수를 얻으려면,PDOStatement
and do 하고 있다rowCount()
, like:예를 들어 다음과 같습니다.
<?php $stmt = $db->query('SELECT * FROM table'); $row_count = $stmt->rowCount(); echo $row_count.' rows selected';
Getting the Last Inserted ID마지막으로 삽입된 ID 가져오기
<?php $result = $db->exec("INSERT INTO table(firstname, lastname) VAULES('John', 'Doe')"); $insertId = $db->lastInsertId();
Insert and Update or Delete statements문 삽입 및 업데이트 또는 삭제
What we are doing in 델이 하고 있는 일mysql_*
function is:기능은 다음과 같습니다.
<?php $results = mysql_query("UPDATE table SET field='value'") or die(mysql_error()); echo mysql_affected_rows($result);
And in pdo, this same thing can be done by:pdo에서는 다음과 같은 작업을 수행할 수 있습니다.
<?php $affected_rows = $db->exec("UPDATE table SET field='value'"); echo $affected_rows;
In the above query PDO::exec
execute an SQL statement and returns the number of affected rows.위의 쿼리에서 SQL 문을 실행하고 영향을 받는 행 수를 반환합니다.
Insert and delete will be covered later.삽입 및 삭제에 대해서는 나중에 설명하겠습니다.
The above method is only useful when you are not using variable in query.위의 방법은 쿼리에서 변수를 사용하지 않는 경우에만 유용합니다. But when you need to use a variable in a query, do not ever ever try like the above and there for prepared statement or parameterized statement is.단, 쿼리에서 변수를 사용해야 할 경우 위와 같이 prepared 스테이트먼트 또는 파라미터화된 스테이트먼트를 시도하지 마십시오.
Prepared Statements준비된 스테이트먼트
Q. What is a prepared statement and why do I need them?Q. 준비된 진술서는 무엇이며 왜 필요한가?
A. A prepared statement is a pre-compiled SQL statement that can be executed multiple times by sending only the data to the server.A. 준비된 문은 미리 컴파일된 SQL 문을 말하며, 서버에 데이터만 전송하여 여러 번 실행할 수 있습니다.
The typical workflow of using a prepared statement is as follows (quoted from Wikipedia three 3 point):준비된 스테이트먼트를 사용하는 일반적인 워크플로는 다음과 같습니다(Wikipedia 3에서 인용).
Prepare:준비: The statement template is created by the application and sent to the database management system (DBMS).스테이트먼트 템플릿은 어플리케이션에 의해 작성되어 Database Management System(DBMS; 데이터베이스 관리 시스템)으로 전송됩니다. Certain values are left unspecified, called parameters, placeholders or bind variables (labelled 파라미터, 플레이스 홀더 또는 바인드 변수(라벨 부착)라고 불리는 특정 값은 지정되지 않은 상태로 남습니다.
?
below):이하에 나타냅니다.INSERT INTO PRODUCT (name, price) VALUES (?, ?)
The DBMS parses, compiles, and performs query optimization on the statement template, and stores the result without executing it.DBMS는 문 템플릿을 구문 분석, 컴파일 및 쿼리 최적화를 수행하고 결과를 실행하지 않고 저장합니다.
- Execute:실행: At a later time, the application supplies (or binds) values for the parameters, and the DBMS executes the statement (possibly returning a result).나중에 응용 프로그램은 파라미터의 값을 제공하고(또는 바인드), DBMS는 문을 실행합니다(결과를 반환할 수 있습니다). The application may execute the statement as many times as it wants with different values.응용 프로그램은 다른 값을 사용하여 원하는 횟수만큼 문을 실행할 수 있습니다. In this example, it might supply ‘Bread’ for the first parameter and 이 예에서는 첫 번째 파라미터에 ‘Bread’를 제공할 수 있습니다.
1.00
for the second parameter.두 번째 파라미터로 설정합니다.
You can use a prepared statement by including placeholders in your SQL.SQL에 자리 표시자를 포함하여 준비된 문을 사용할 수 있습니다. There are basically three ones without placeholders (don’t try this with variable its above one), one with unnamed placeholders, and one with named placeholders.기본적으로 플레이스 홀더가 없는 것은 세 가지(위의 변수와 함께 시도하지 않음), 이름 없는 플레이스 홀더가 있는 플레이스 홀더와 이름 있는 플레이스 홀더가 있는 플레이스 홀더가 있는 플레이스 홀더가 있습니다.
Q. So now, what are named placeholders and how do I use them?Q. 그럼 플레이스 홀더란 무엇이며 어떻게 사용해야 합니까?
A. Named placeholders.A. 이름 있는 플레이스 홀더. Use descriptive names preceded by a colon, instead of question marks.물음표 대신 콜론 앞에 설명적인 이름을 사용합니다. We don’t care about position/order of value in name place holder:이름 자리 보유자의 위치/값 순서는 상관없습니다.
$stmt->bindParam(':bla', $bla);
bindParam(parameter,variable,data_type,length,driver_options)
You can also bind using an execute array as well:실행 어레이를 사용하여 바인드할 수도 있습니다.
<?php $stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name"); $stmt->execute(array(':name' => $name, ':id' => $id)); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
Another nice feature for 또 하나의 뛰어난 기능OOP
friends is that named placeholders have the ability to insert objects directly into your database, assuming the properties match the named fields.friends는 지정된 플레이스홀더가 지정된 필드와 속성이 일치한다고 가정할 때 데이터베이스에 오브젝트를 직접 삽입할 수 있는 기능입니다. For example:예를 들어 다음과 같습니다.
class person { public $name; public $add; function __construct($a,$b) { $this->name = $a; $this->add = $b; } } $demo = new person('john','29 bla district'); $stmt = $db->prepare("INSERT INTO table (name, add) value (:name, :add)"); $stmt->execute((array)$demo);
Q. So now, what are unnamed placeholders and how do I use them?Q. 그럼 이름 없는 플레이스 홀더는 무엇이며 어떻게 사용해야 합니까?
A. Let’s have an example:A. 예를 들어 보겠습니다.
<?php $stmt = $db->prepare("INSERT INTO folks (name, add) values (?, ?)"); $stmt->bindValue(1, $name, PDO::PARAM_STR); $stmt->bindValue(2, $add, PDO::PARAM_STR); $stmt->execute();
and그리고.
$stmt = $db->prepare("INSERT INTO folks (name, add) values (?, ?)"); $stmt->execute(array('john', '29 bla district'));
In the above, you can see those 위에서 볼 수 있습니다.?
instead of a name like in a name place holder.네임플레이스 홀더에 있는 이름 대신. Now in the first example, we assign variables to the various placeholders (첫 번째 예에서는 다양한 플레이스 홀더에 변수를 할당합니다($stmt->bindValue(1, $name, PDO::PARAM_STR);
). Then, we assign values to those placeholders and execute the statement.그런 다음 플레이스 홀더에 값을 할당하고 문을 실행합니다. In the second example, the first array element goes to the first 두 번째 예에서는 첫 번째 배열 요소가 첫 번째 배열 요소로 이동합니다.?
and the second to the second 그리고 두 번째에서 두 번째까지?
..
NOTE: In unnamed placeholders we must take care of the proper order of the elements in the array that we are passing to the 메모: 이름 없는 플레이스 홀더에서는 어레이 내에서 전달되는 요소의 올바른 순서를 관리할 필요가 있습니다.PDOStatement::execute()
method.방법.
SELECT
, ,INSERT
, ,UPDATE
, ,DELETE
prepared queries준비된 쿼리
SELECT
:다음과 같습니다SELECT
.$stmt = $db->prepare("SELECT * FROM table WHERE id=:id AND name=:name"); $stmt->execute(array(':name' => $name, ':id' => $id)); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
INSERT
:다음과 같습니다INSERT
.$stmt = $db->prepare("INSERT INTO table(field1,field2) VALUES(:field1,:field2)"); $stmt->execute(array(':field1' => $field1, ':field2' => $field2)); $affected_rows = $stmt->rowCount();
DELETE
:다음과 같습니다DELETE
.$stmt = $db->prepare("DELETE FROM table WHERE id=:id"); $stmt->bindValue(':id', $id, PDO::PARAM_STR); $stmt->execute(); $affected_rows = $stmt->rowCount();
UPDATE
:다음과 같습니다UPDATE
.$stmt = $db->prepare("UPDATE table SET name=? WHERE id=?"); $stmt->execute(array($name, $id)); $affected_rows = $stmt->rowCount();
NOTE:주의:
However 하지만PDO
and/or 및/또는MySQLi
are not completely safe.완전히 안전하지 않습니다. Check the answer Are PDO prepared statements sufficient to prevent SQL injection?“PDO 준비 문장은 SQL 주입을 방지하기에 충분한가?”라는 답변을 확인합니다. by ircmaxell.ircmaxell에 의해. Also, I am quoting some part from his answer:또, 나는 그의 대답의 일부를 인용하고 있다.
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->query('SET NAMES GBK'); $stmt = $pdo->prepare("SELECT * FROM test WHERE name = ? LIMIT 1"); $stmt->execute(array(chr(0xbf) . chr(0x27) . " OR 1=1 /*"));
First, let’s begin with the standard comment we give everyone: 먼저, 모든 고객에게 제공하는 표준적인 코멘트부터 시작하겠습니다.
Please, don’t use
mysql_*
functions in new code.새로운 코드의 함수는 사용하지 말아 주세요. They are no longer maintained and are officially deprecated.그것들은 더 이상 유지되지 않고 공식적으로 폐지된다. See the red box?빨간 상자 보이지? Learn about prepared statements instead, and use PDO or MySQLi – this article will help you decide which.대신 준비된 문장에 대해 알아보고 PDO 또는 MySQLi를 사용하십시오. 이 문서는 어떤 문장이 어떤 것인지 결정하는 데 도움이 됩니다. If you choose PDO, here is a good tutorial.PDO를 선택한 경우 다음 튜토리얼을 참고하십시오.
Let’s go through this, sentence by sentence, and explain:그럼 한 문장 한 문장씩 살펴보고 설명하겠습니다.
They are no longer maintained, and are officially deprecated그것들은 더 이상 유지되지 않고 공식적으로 폐지된다.
This means that the PHP community is gradually dropping support for these very old functions.이는 PHP 커뮤니티가 이러한 매우 오래된 기능에 대한 지원을 점차 중단하고 있음을 의미합니다. They are likely to not exist in a future (recent) version of PHP!PHP의 미래(최근) 버전에는 존재하지 않을 수 있습니다! Continued use of these functions may break your code in the (not so) far future.이러한 기능을 계속 사용하면 앞으로 코드가 깨질 수 있습니다(그렇지 않을 수도 있습니다.
NEW! – ext/mysql is now officially deprecated as of PHP 5.5!신규! – PHP 5.5에서 ext/mysql은 공식적으로 폐지되었습니다!
Newer! ext/mysql has been removed in PHP 7.최신! ext/mysql이 PHP 7에서 제거되었습니다.
Instead, you should learn of prepared statements대신, 당신은 준비된 문장을 배워야 합니다.
mysql_*
extension does not support prepared statements, which is (among other things) a very effective countermeasure against SQL Injection.extension은 SQL Injection에 대한 매우 효과적인 대책인 준비된 문을 지원하지 않습니다. It fixed a very serious vulnerability in MySQL dependent applications which allows attackers to gain access to your script and perform any possible query on your database.이를 통해 MySQL 종속 응용 프로그램의 매우 심각한 취약성을 수정하여 공격자가 스크립트에 액세스하고 데이터베이스에서 가능한 쿼리를 수행할 수 있습니다.For more information, see How can I prevent SQL injection in PHP?자세한 내용은 PHP에서 SQL 주입을 방지하는 방법을 참조하십시오.
See the Red Box?빨간 상자 보여?
When you go to any 아무데나 가면
mysql
function manual page, you see a red box, explaining it should not be used anymore.기능 매뉴얼 페이지에 빨간색 상자가 표시되어 더 이상 사용하지 않아야 함을 설명합니다.Use either PDO or MySQLiPDO 또는 MySQLi 사용
There are better, more robust and well-built alternatives, PDO – PHP Database Object, which offers a complete OOP approach to database interaction, and MySQLi, which is a MySQL specific improvement.데이터베이스 상호 작용에 대한 완전한 OOP 접근 방식을 제공하는 PDO – PHP Database Object와 MySQL 고유의 개선점인 MySQLi 등 보다 우수하고 견고하며 잘 구축된 대안이 있습니다.
Ease of use사용의 용이성
The analytic and synthetic reasons were already mentioned.분석적 이유와 종합적 이유는 이미 언급되었다. For newcomers there’s a more significant incentive to stop using the dated mysql_ functions.새로 온 사람에게는 날짜 mysql_ 함수의 사용을 중지하는 것이 더 큰 인센티브입니다.
Contemporary database APIs are just easier to use.최신 데이터베이스 API는 사용하기가 더 쉬울 뿐입니다.
It’s mostly the bound parameters which can simplify code.코드를 단순화할 수 있는 것은 대부분 바운드 파라미터입니다. And with excellent tutorials (as seen above) the transition to PDO isn’t overly arduous.또, 뛰어난 튜토리얼(상기 참조)을 사용하고 있기 때문에, PDO로의 이행은 그다지 어렵지 않습니다.
Rewriting a larger code base at once however takes time.단, 한 번에 더 큰 코드 베이스를 다시 쓰려면 시간이 걸립니다. Raison d’être for this intermediate alternative:이 중간 대안을 위한 Raison d’étre:
Equivalent pdo_* functions in place of mysql_*mysql_* 대신 동등한 pdo_* 함수
Using <pdo_mysql.php> you can switch from the old mysql_ functions with minimal effort.<pdo_mysql.php>를 사용하면 최소한의 노력으로 오래된 mysql_ 함수에서 전환할 수 있습니다. It adds 가세하다pdo_
function wrappers which replace their 기능 래퍼를 대체하다mysql_
counterparts.상대편
Simply 간단하게
include_once(
"pdo_mysql.php"
);
in each invocation script that has to interact with the database.데이터베이스와 상호 작용해야 하는 각 호출 스크립트에서 사용됩니다.Remove the
function prefix everywhere and replace it withmysql_
pdo_
.함수 프리픽스를 삭제하고 로 교체합니다.mysql_
connect()
becomespdo_
가 되다connect()
mysql_
query()
becomespdo_
가 되다query()
mysql_
num_rows()
becomespdo_
가 되다num_rows()
mysql_
insert_id()
becomespdo_
가 되다insert_id()
mysql_
fetch_array()
becomespdo_
가 되다fetch_array()
mysql_
fetch_assoc()
becomespdo_
가 되다fetch_assoc()
mysql_
real_escape_string()
becomespdo_
가 되다real_escape_string()
- and so on…기타 등등…
Your code will work alike and still mostly look the same:코드는 동일하게 동작하지만 대부분 동일하게 표시됩니다.
include_once("pdo_mysql.php"); pdo_connect("localhost", "usrABC", "pw1234567"); pdo_select_db("test"); $result = pdo_query("SELECT title, html FROM pages"); while ($row = pdo_fetch_assoc($result)) { print "$row[title] - $row[html]"; }
Et voilà.엣보일라
Your code is using PDO.코드가 PDO를 사용하고 있습니다.
Now it’s time to actually utilize it.이제 실제로 활용할 때입니다.
Bound parameters can be easy to use바운드 파라미터의 사용이 용이함
You just need a less unwieldy API.덜 다루기 쉬운 API만 있으면 됩니다.
pdo_query()
adds very facile support for bound parameters.는 바인딩된 파라미터에 대한 매우 쉬운 지원을 추가합니다. Converting old code is straightforward:이전 코드 변환은 간단합니다.
Move your variables out of the SQL string.SQL 문자열에서 변수를 이동합니다.
- Add them as comma delimited function parameters to 이들을 콤마로 구분된 함수 파라미터로 추가합니다.
pdo_query()
.. - Place question marks 물음표 배치
?
as placeholders where the variables were before.자리 표시자로 사용할 수 있습니다. - Get rid of 제거하다
'
single quotes that previously enclosed string values/variables.이전에 문자열 값 또는 문자열을 묶은 작은 따옴표.
The advantage becomes more obvious for lengthier code.코드의 길이가 길수록 이점이 더욱 뚜렷해집니다.
Often string variables aren’t just interpolated into SQL, but concatenated with escaping calls in between.대부분의 문자열 변수는 SQL에 보간될 뿐만 아니라 중간에 이스케이프 콜과 연결됩니다.
pdo_query("SELECT id, links, html, title, user, date FROM articles WHERE title='" . pdo_real_escape_string($title) . "' OR id='". pdo_real_escape_string($title) . "' AND user <> '" . pdo_real_escape_string($root) . "' ORDER BY date")
With 와 함께?
placeholders applied you don’t have to bother with that:플레이스 홀더 신청은 번거롭지 않습니다.
pdo_query("SELECT id, links, html, title, user, date FROM articles WHERE title=? OR id=? AND user<>? ORDER BY date", $title, $id, $root)
Remember that pdo_* still allows either or.pdo_*는 여전히 또는 둘 중 하나를 허용합니다.
Just don’t escape a variable and bind it in the same query.변수를 이스케이프하지 말고 동일한 쿼리에 바인딩하십시오.
- The placeholder feature is provided by the real PDO behind it.플레이스 홀더 기능은 플레이스 홀더 뒤에 있는 실제 PDO에 의해 제공됩니다.
- Thus also allowed 그러므로 또한 허용된다.
:named
placeholder lists later.나중에 플레이스 홀더 리스트를 참조해 주세요.
More importantly you can pass $_REQUEST[] variables safely behind any query.더 중요한 것은 $_REQUEST[] 변수를 쿼리 뒤에 안전하게 전달할 수 있다는 것입니다. When submitted 제출 시<form>
fields match the database structure exactly it’s even shorter:필드는 데이터베이스 구조와 정확히 일치합니다.
pdo_query("INSERT INTO pages VALUES (?,?,?,?,?)", $_POST);
So much simplicity.너무 단순해요. But let’s get back to some more rewriting advises and technical reasons on why you may want to get rid of and escaping.하지만 왜 제거하거나 탈출하고 싶은지에 대한 몇 가지 조언과 기술적인 이유로 돌아가 봅시다.mysql_
Fix or remove any oldschool sanitize()
function구식 기능 수정 또는 제거
Once you have converted all calls to 모든 콜을 로 변환하면mysql_
pdo_query
with bound params, remove all redundant 바인드된 매개 변수를 사용하여 모든 중복 제거pdo_real_escape_string
calls.콜을 클릭합니다.
In particular you should fix any 특히 수정해야 합니다.sanitize
or 또는clean
or 또는filterThis
or 또는clean_data
functions as advertised by dated tutorials in one form or the other:는 다음 중 하나의 형식으로 날짜가 지난 튜토리얼에 의해 애드버타이즈된 기능을 합니다.
function sanitize($str) { return trim(strip_tags(htmlentities(pdo_real_escape_string($str)))); }
Most glaring bug here is the lack of documentation.여기서 가장 눈에 띄는 문제는 문서화의 부족이다. More significantly the order of filtering was in exactly the wrong order.더 중요한 것은 필터링 순서가 정확히 잘못되었다는 것입니다.
Correct order would have been: deprecatedly 올바른 순서는 다음과 같습니다: 권장되지 않음
stripslashes
as the innermost call, then 그럼 제일 안쪽의 전화로서trim
, afterwards , 그 후strip_tags
, ,htmlentities
for output context, and only lastly the 출력 콘텍스트의 경우,_escape_string
as its application should directly preceed the SQL intersparsing.응용 프로그램이 SQL 인터스패싱에 직접 선행해야 하기 때문입니다.But as first step just get rid of the
_real_escape_string
call.하지만 첫 번째 단계로 콜을 제거합니다.You may have to keep the rest of your 나머지 부분은 보관해야 할 수도 있습니다.
sanitize()
function for now if your database and application flow expect HTML-context-safe strings.데이터베이스와 어플리케이션플로우가 HTML 컨텍스트 세이프 스트링을 요구하고 있는 경우는, 현시점에서는 기능합니다. Add a comment that it applies only HTML escaping henceforth.이후 HTML 이스케이프만 적용된다는 주석을 추가합니다.String/value handling is delegated to PDO and its parameterized statements.문자열/값 처리는 PDO 및 해당 매개 변수화된 문에 위임됩니다.
If there was any mention of 에 대한 언급이 있었다면
stripslashes()
in your sanitize function, it may indicate a higher level oversight.sanitize 기능에서는 더 높은 수준의 감시를 나타낼 수 있습니다.That was commonly there to undo damage (double escaping) from the deprecated
magic_quotes
.그것은 일반적으로 폐지된 로부터의 파손(이중 탈출)을 복구하기 위해 있었다. Which however is best fixed centrally, not string by string.단, 스트링별로가 아니라 중앙에서 수정하는 것이 가장 좋습니다.Use one of the userland reversal approaches.사용자 랜드 반전 접근법 중 하나를 사용합니다. Then remove the 그런 다음 를 삭제합니다.
stripslashes()
in the 에서sanitize
function.기능.
Historic note on magic_quotes.magic_quotes의 이력 노트. That feature is rightly deprecated.그 기능은 당연히 권장되지 않는다. It’s often incorrectly portrayed as failed security feature however.그러나 보안 기능 장애로 잘못 묘사되는 경우가 많습니다. But magic_quotes are as much a failed security feature as tennis balls have failed as nutrition source.그러나 magic_quotes는 테니스공이 영양 공급원만큼 실패한 보안 기능입니다. That simply wasn’t their purpose.그것은 단순히 그들의 목적이 아니었다.
The original implementation in PHP2/FI introduced it explicitly with just “quotes will be automatically escaped making it easier to pass form data directly to msql queries“.PHP2/FI의 원래 구현에서는 “인용어가 자동으로 이스케이프되므로 폼 데이터를 msql 쿼리에 직접 전달하기가 더 쉬워집니다.”라고 명시되어 있습니다. Notably it was accidentially safe to use with mSQL, as that supported ASCII only.특히 ASCII만 지원하므로 mSQL에서 사용하는 것은 우발적으로 안전합니다.
Then PHP3/Zend reintroduced magic_quotes for MySQL and misdocumented it.그 후 PHP3/Zend는 MySQL용 magic_quotes를 재도입하여 잘못 문서화하였습니다. But originally it was just a convenience feature, not intend for security.그러나 원래 이것은 보안을 목적으로 한 것이 아니라 편의 기능일 뿐입니다.
How prepared statements differ준비된 진술이 어떻게 다른가
When you scramble string variables into the SQL queries, it doesn’t just get more intricate for you to follow.문자열 변수를 SQL 쿼리에 스크램블하면 더 복잡해질 뿐만 아니라 It’s also extraneous effort for MySQL to segregate code and data again.MySQL은 코드와 데이터를 다시 분리하는 작업도 불필요합니다.
SQL injections simply are when data bleeds into code context.SQL 주입은 단순히 데이터가 코드 컨텍스트에 블리딩되는 경우입니다. A database server can’t later spot where PHP originally glued variables inbetween query clauses.데이터베이스 서버는 나중에 쿼리 구 사이에 원래 PHP가 붙어 있던 변수를 찾을 수 없습니다.
With bound parameters you separate SQL code and SQL-context values in your PHP code.경계 매개 변수를 사용하여 PHP 코드에서 SQL 코드와 SQL 컨텍스트 값을 구분합니다. But it doesn’t get shuffled up again behind the scenes (except with PDO::그러나 이 문제는 뒷전에서는 다시 일어나지 않습니다(PDO 제외:EMULATE_PREPARES).에뮬레이트_PREPARES). Your database receives the unvaried SQL commands and 1:1 variable values.데이터베이스는 변경되지 않은 SQL 명령과 1:1 변수 값을 수신합니다.
While this answer stresses that you should care about the readability advantages of dropping .이 답변에서는 drop의 가독성 이점에 유의해야 한다고 강조합니다. There’s occasionally also a performance advantage (repeated INSERTs with just differing values) due to this visible and technical data/code separation.이러한 가시적이고 기술적인 데이터/코드 분리에 의해 퍼포먼스가 향상되는 경우가 있습니다(INSERT의 값이 다른 반복). mysql_
Beware that parameter binding still isn’t a magic one-stop solution against all SQL injections.파라미터 바인딩은 여전히 모든 SQL 주입에 대한 마법의 원스톱 솔루션이 아닙니다. It handles the most common use for data/values.데이터/값의 가장 일반적인 용도를 처리합니다. But can’t whitelist column name / table identifiers, help with dynamic clause construction, or just plain array value lists.그러나 열 이름/테이블 식별자, 동적 절 구성 또는 일반 배열 값 목록만 화이트리스트로 만들 수는 없습니다.
Hybrid PDO use하이브리드 PDO 사용
These 이것들pdo_*
wrapper functions make a coding-friendly stop-gap API. (It’s pretty much what wrapper 함수는 코딩 친화적인 임시 API를 만듭니다.MYSQLI
could have been if it wasn’t for the idiosyncratic function signature shift).특이한 기능 시그니처 시프트가 없었다면 가능했을 것입니다). They also expose the real PDO at most times.또한 대부분의 경우 실제 PDO를 노출합니다.
Rewriting doesn’t have to stop at using the new pdo_ function names.새 pdo_ 함수 이름을 사용하여 다시 쓸 필요가 없습니다. You could one by one transition each pdo_query() into a plain $pdo->prepare()->execute() call.각 pdo_query()를 플레인 $pdo->prepare()->execute()콜로 하나씩 이행할 수 있습니다.
It’s best to start at simplifying again however.그러나 다시 단순화하는 것이 가장 좋습니다. For example the common result fetching:예를 들어 일반적인 결과 가져오기:
$result = pdo_query("SELECT * FROM tbl"); while ($row = pdo_fetch_assoc($result)) {
Can be replaced with just an foreach iteration:포어치 반복만으로 대체할 수 있습니다.
foreach ($result as $row) {
Or better yet a direct and complete array retrieval:또는 직접적이고 완전한 어레이 취득:
$result->fetchAll();
You’ll get more helpful warnings in most cases than PDO or mysql_ usually provide after failed queries.대부분의 경우 쿼리 실패 후 PDO 또는 mysql_보다 더 유용한 경고가 표시됩니다.
Other options기타 옵션
So this hopefully visualized some practical reasons and a worthwile pathway to drop .그래서 이것은 희망적으로 몇 가지 실제적인 이유와 떨어뜨리는 가치 있는 경로를 시각화했다.mysql_
Just switching to pdo doesn’t quite cut it.pdo로 바꾸는 것만으로는 충분치 않아요. pdo_query()
is also just a frontend onto it.앞부분일 뿐이죠.
Unless you also introduce parameter binding or can utilize something else from the nicer API, it’s a pointless switch.파라미터 바인딩을 도입하거나 보다 좋은 API에서 다른 것을 이용할 수 없는 한 의미 없는 스위치입니다. I hope it’s portrayed simple enough to not further the discouragement to newcomers. (Education usually works better than prohibition.)새내기에게 더 이상 낙담하지 않을 정도로 단순하게 묘사되었으면 좋겠다. (보통 교육은 금지보다 효과가 있다.)
While it qualifies for the simplest-thing-that-could-possibly-work category, it’s also still very experimental code.가장 간단한 작업 범주에 해당하지만 여전히 매우 실험적인 코드입니다. I just wrote it over the weekend.주말에 썼어. There’s a plethora of alternatives however.하지만 너무 많은 대안이 있다. Just google for PHP database abstraction and browse a little.PHP 데이터베이스 추상화를 구글에서 검색하여 조금만 참조하면 됩니다. There always have been and will be lots of excellent libraries for such tasks.이러한 작업을 위한 훌륭한 도서관은 항상 존재해 왔고 앞으로도 존재하게 될 것입니다.
If you want to simplify your database interaction further, mappers like Paris/Idiorm are worth a try.데이터베이스 상호 작용을 더욱 단순화하고 싶다면 Paris/Idiorm과 같은 매핑을 시도해 볼 만하다. Just like nobody uses the bland DOM in JavaScript anymore, you don’t have to babysit a raw database interface nowadays.JavaScript에서 아무도 DOM을 사용하지 않는 것처럼, 오늘날에는 원시 데이터베이스 인터페이스를 돌볼 필요가 없습니다.
The 그mysql_
functions:기능:
- are out of date – they’re not maintained any more구식 – 더 이상 유지보수가 되지 않습니다.
- don’t allow you to move easily to another database backend다른 데이터베이스 백엔드로 쉽게 이동할 수 없음
- don’t support prepared statements, hence준비된 스테이트먼트를 지원하지 않기 때문에
- encourage programmers to use concatenation to build queries, leading to SQL injection vulnerabilities프로그래머가 쿼리를 작성하기 위해 연결을 사용하도록 권장하여 SQL 주입 취약성을 야기합니다.