mysql:database_api
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
mysql:database_api [2016/10/13 15:51] – created peter | mysql:database_api [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== MySQL - Database API ====== | ====== MySQL - Database API ====== | ||
+ | |||
+ | PHP offers three different APIs to connect to MySQL. | ||
===== Choosing an API ===== | ===== Choosing an API ===== | ||
- | http://php.net/manual/en/mysqlinfo.api.choosing.php | + | Comparing the three MySQL APIs. |
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | // PDO | ||
+ | $pdo = new PDO(' | ||
+ | $statement = $pdo-> | ||
+ | $row = $statement-> | ||
+ | echo htmlentities($row[' | ||
+ | |||
+ | // mysqli | ||
+ | $mysqli = new mysqli(" | ||
+ | $result = $mysqli-> | ||
+ | $row = $result-> | ||
+ | echo htmlentities($row[' | ||
+ | |||
+ | // mysql | ||
+ | $c = mysql_connect(" | ||
+ | mysql_select_db(" | ||
+ | $result = mysql_query(" | ||
+ | $row = mysql_fetch_assoc($result); | ||
+ | echo htmlentities($row[' | ||
+ | ?> | ||
+ | </code> | ||
+ | |||
+ | It is recommended to use either the PDO_MySQL or mysqli extensions. It is not recommended to use the old mysql extension for new development, | ||
+ | |||
+ | PDO has the advantage that you only need to learn one PHP API if you need to work with different DBMS in the future. | ||
+ | |||
+ | MySQLi is more powerful and probably more complex to learn. | ||
Line 9: | Line 40: | ||
http:// | http:// | ||
+ | |||
+ | |||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | http:// | ||
+ |
mysql/database_api.1476373873.txt.gz · Last modified: 2020/07/15 09:30 (external edit)