Journal

How to write databse query in mysql,pdo and mysqli format?

Databse query in mysql,pdo and mysqli format.

MySQL = Popular open source relational database management system.
MySQLi - Improved PHP MySQL extension Read here
PDO - PHP extension similar to MySQLi. Provides object oriented way to access database

MySqli

$mysqli =new mysqli("example.com","user","password","database"); 
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc(); echo htmlentities($row['_message']);

PDO

$pdo =new PDO('mysql:host=example.com;dbname=database','user','password'); 
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC); echo htmlentities($row['_message']);

MySQL

$c = mysql_connect("example.com","user","password"); 
mysql_select_db("database");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result); echo htmlentities($row['_message']);

Ad comes here
Comments
Leave A Comment
PHP blog