PDA

View Full Version : Running PHP and MYSQL


ptrcklgrs
04-14-2006, 10:38 PM
Ok i have used xampp to set up a database and a table on my http://localhost using phpmyadmin and i have all programs running fine then i open up a PHP file using dreamweaver and enter the code.

$username="username";
$password="password";
$database="dtest";


then it says to use this command to get started but when i do it gives me an error messege

mysql_connect(localhost,$username,$password);

my database is called dtest and my table is called ttest and im not sure what is my username or password because i never "set one up" also my localhost is the htdocs default folder that xampp uses. How do i get connected because i think thats where my problem is. If you need additional info PLEASE LET ME KNOW and i will tell you whatever you need to help me.
Thank you for even taking the time to read this.

Flash Gordon
04-14-2006, 10:44 PM
first what is the error message
second, mysql does NOT run by default whenever your fire up xampp. Go check the "status" at the home page http://localhost/ and click status and you will see mySQL is not running.
Third, set up the database with a user and pass.

cheers

Flash Gordon
04-14-2006, 11:32 PM
Here is some code to get you started:

//--------define connectivity information
$database = "*****";
$table = "*****";
$user = "******";
$password = "*******";
//-------connect to database
mysql_connect("localhost", $user, $password) or die("Could not connect to database");
mysql_select_db($database) or die("Could not select database");
//-------Query database
$query = "SELECT * FROM $table";
$myQuery = mysql_query($query);
//-------manage data
while($row = mysql_fetch_array($myQuery)) {
$id[] = $row['id'];
$date[] = $row['date'];
$time[] = $row['time'];
$venue[] = $row['venue'];
$details[] = $row['details'];
}

//------close connection
mysql_close();