Home >Unlabelled > PHP PDO MySQL - Simple Example Connecting to MySQL With PDO Class
PHP PDO MySQL - Simple Example Connecting to MySQL With PDO Class
Posted on Minggu, 27 November 2011 by Yana Xena
I'll demonstrate a simple example on how to connect to MySQL using PHP's PDO class. Just some of the benefits of PDO is that it's fast and if you use the PDO::prepare() method it will prevent SQL injection attacks by calling the PDO::quote() method. The other pros is that there are several databases it will support. So let's dive right into the code:
$ hostname = 'localhost';
$ username = 'your_username';
$ password = 'your_password';
try {
$ db = new PDO("mysql:host=$
Diberdayakan oleh Blogger.