I am able to connect to mysql but not to a database. This is the code I am trying to execute.
There is not result from the above code when I run it using the browser.
I was able to verify that I can connect to mysql by using the following code:
Thank you.
Asfaw
Code:
<?php
// Establish a connection to the MySQL DBMS
$connection = mysql_connect("localhost", "root", "");
// Use the winestore database
mysql_select_db("winestore", $connection);
// Run a query through the connection
$result = mysql_query("SELECT cust_id, surname, firstname FROM Customer", $connection);
// Fetch each row of the results into an array $row
while ($row = mysql_fetch_array($result)
{
print "ID:\t{$row["cust_id"]}\n";
print "Surname\t{$row["surname"]}\n";
print "First Name:\t{$row["firstname"]}\n\n";
}
?>
I was able to verify that I can connect to mysql by using the following code:
Code:
<?php
$link = mysql_connect("localhost", "root", "");
if (!$link) {
// unable to connect to database
echo 'Failed to connect';
}
else {
// you were able to connect to the database
echo 'Database connect succeeded';
}
?>
Asfaw