Viewers: in countries Watching now:
Now that PHP has true object-oriented capabilities, it's best practice to access databases using PDO (PHP Data Objects) and MySQLi. These methods produce database-neutral code that works with over a dozen systems, including MySQL, SQL Server, PostgreSQL, and SQLite. Learn how to use PDO and MySQLi to perform basic select, insert, update, and delete operations; improve security with prepared statements; and use transactions to execute multiple queries simultaneously. Author David Powers also covers advanced topics like instantiating custom objects, and compares PDO to MySQLi so you can decide which method is right for you.
If you work exclusively in English, you probably don't need to worry about the character set used by MySQL. But, if you work with languages that use accented characters, or different writing systems, the character set used by MySQL effects the way PHP handles quotes and character escaping, when interacting with the database. This has important security implications when handling user input from online forms. Ideally, the character set should be set on the database server. However, it can be changed using SQL statements.
For example, set names utf8, or set character set utf8, will change the character set for the current connection. But, there's an important catch. PHP will not use the character set defined by a query when handling quotes and escaping characters. You must use the MySQLi set_charset() method. To set the character set, open MYSQLi_connect.php in the includes folder. And, call the set, jar set method, on the database connection object, like this. So, it's db, the arrow operator, then set char set, and the value is passed as a string, utf8, and that's all that's necessary. You just need to save the page and that's it.
This not only sets the character set for the current connection to MySQL, it also insures that PHP handles quotes and escape characters correctly. UTF-8 should be appropriate for the vast majority of web applications. But, this page in the MySQL online documentation, describes how to find out which character sets are supported by your version of MySQL.
There are currently no FAQs about Accessing Databases with Object-Oriented PHP.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.