Join Login


Video Tutorials
Blog



PrintPlace.com Online Full Color Printing

Connect to a MySQL Database


By: RiverCityGraphix      Views: 6675      Share: Bookmark and Share

In this tutorial, you will learn how to connect to a MySQL database using PHP.

Once you have created your database and set up a table within it, you still can not add data into it or take it from the database by using PHP. You still need to establish a connection between your PHP file and the MySQL database. It is quite simple and can be easily included into any file in the future that requires MySQL data. Save this code into a separate file and it will be as easy as one line of code to include it from now on.

<?php

$db_host = "localhost";
$db_username = "root";
$db_pass = "test123";
$db_name = "test_database";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to MySQL");
@mysql_select_db("$db_name") or die ("No database");

?>




Free Source Files Zip

Full Color Brochures from PrintPlace.com