We have seen how to fetch youtube videos using simple javascript in our previous tutorial. Today's tutorial is about connecting our database using PHP. Since PHP is a dynamic scripting language and it uses mysql database in the back end to store the data. That means the php file has to be configured to connect the database. This can be done very easily with a simple php code. This tutorial will help you to connect to the database. The database connection needs four parameters to be passed into two functions. mysql_connect() and mysql_select_db() are the two functions to connect to the database.
mysql_connect() function requires three parameters and this function is used to connect to the database. and mysql_select_db() function is used to select the database.
Here is the simple code that you can simply copy and use to connect your database with php.
Please don't hesitate to ask your queries. Thank you
mysql_connect() function requires three parameters and this function is used to connect to the database. and mysql_select_db() function is used to select the database.
Here is the simple code that you can simply copy and use to connect your database with php.
<?phpNow replace root with your database username database_password with your database password database_name with your database username. That's it, you are done.
$dbhost = "localhost"; //host name (usually localhost)
$dbuser = "root"; //your database(mysql) user name
$dbpass = "database_password"; //your database (mysql) password
$dbname = "database_name"; //database name
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to database");
mysql_select_db($dbname) or die ("Error selecting the database");
?>
Please don't hesitate to ask your queries. Thank you
0 comments:
Post a Comment