Monday, October 8, 2012

Test MySQL connection in php using xampp

XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin.
XAMPP Web Site

Go to http://localhost/phpmyadmin/ after installing xampp
create database "test" under Database tab. Under "Users", check database username "root", host "localhost", password "no" for default

My default working directory is: C:\xampp\htdocs\xampp\
 Create a directory phptest, input the following script in test.php:
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "test";

{echo "connect to MySQL server ".$db_host." with username ".$db_username."<br />";}
else die ("could not connect to mysql");
{echo "connect to dtabase ".$db_name;}
else die("no database");            


If everything is OK, the result should return:
connect to MySQL server localhost with username root
connect to dtabase test

No comments:

Post a Comment