PHP has three standard APIs for database connections:
MYSQLi – MySQL Improved
PDO – PHP Data Objects (Best)

The traditional mysql API certainly gets the job done, and has become so popular largely due to the fact that it makes the process of retrieving some records from a database as easy as possible.

A typical Example is shown below

# Connection to a specific database
mysql_connect(‘host_machine’, ‘your_username’, ‘your_password’) or die(‘Connection failed: ‘ . mysql_error());

# Selecting a database
mysql_select_db(‘Your_database’) or die(‘Database connection failed’);

# Retrieve records from the database
[php] $sql = "SELECT username, password FROM table_name";
$statement = mysql_query($query) ;

# Display the result

while ($rs = mysql_fetch_array($statement)) {
echo $rs[‘username’];

Simple, but has some significant downsides
1) It is officially deprecated.
2) Difficult to sanitize input because the developer will have to do it himself
3) Code above can only work with MYSQL the API does not support other database


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: