Failed database connection
Posted: Thu Sep 16, 2010 5:25 am
Hi, i'm new to php and i'm trying to connect to a database that I've made with phpMyAdmin.
I exported the database as a .sql file en added it to my project folder
when I run my project it always says no rows found.
This is the first time I'm trying to connect to a db with php so i think it's a stupid mistake.
This is my script
I exported the database as a .sql file en added it to my project folder
when I run my project it always says no rows found.
This is the first time I'm trying to connect to a db with php so i think it's a stupid mistake.
This is my script
Code: Select all
<?php
// set database server access variables:
$host = "127.0.0.1";
$user = "";
$pass = "";
$db = "upload.sql";
// open connection
$connection = mysql_connect($host, $user, $pass);
// select database
mysql_select_db($db);
// create query
$query = "SELECT * FROM tblupload";
// execute query
$result = mysql_query($query);
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>" . $row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>