Connecting to a database
By admin | December 18, 2007
Connecting to a database through php is not a tough task.
First off all create a new sql database in phpmyadmin and see the privileges section in it for the user/pass by default it is
Username == “root”
Password == “”
In php you need this and your host name it is always localhost
Syntax:
$host = "localhost"; //Host name
$username = "root"; // Username
$pass = ""; //Password
$dbname = "useless"; //Database Name
$connect = mysqli_connect ($host,$username,$pass,$dbname);
if(! $connect)
{
echo “unable to connect to the database”;
}
else{
echo “Connected to database”;
}
?>
The above script will connect you to the database note you must php 5
because it uses mysqli functions
Thanks
krates
Topics: PHP | Comments Off on Connecting to a database
Related Links: