Simple tutorial on php mysql

Hello, here is a little tutorial on managing databases using PHP

To connect to your database we can use the function mysql_connect () that accepts three arguments:
* The host name
* User Name
* Password
This function returns the MySQL connection id on success or FALSE on failure

$connection = mysql_connect ("localhost", "root", "password");
if (! $connection)
die ("can not connect");

To close the connection, we use the mysql_close function () This function takes as argument the variable returned by mysql_connect

mysql_close ($ connection);

Select the database using mysql_select_db() function. This function takes as argument the name of the database

$MyDatabase = "database";
mysql_select_db ($MyDatabase)

To perform operation on the database use the mysql_query() function. This function takes as argument a string containing the SQL query.

$query = "SELECT * FROM Article", / / request
mysql_query ($query, $ connection); / / execute the query

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.