Reputation: 5550
Please consider the following code. I believe it's very straight forward however I couldn't see what's wrong with it.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT cif, br,
fullname, id, id_type,issuance_country,class
FROM ciftable';
mysql_select_db('ciftable');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "CIF :{$row['cif']} <br> ".
"BR : {$row['br']} <br> ".
"Full Name : {$row['fullname']} <br> ".
"ID : {$row['id']} <br> ".
"ID Type: {$row['id_type']} <br> ".
"Issuance Country : {$row['issuance_country']} <br> ".
"Class : {$row['class']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
mysql_close($conn);
?>
This is the fresh installation of xampp so will be using default username and password. Kindly ignore all the possible SQL injection or best practices.
The above code throwing exception:
Could not get data: No database selected
Kindly advise.
Upvotes: 0
Views: 162
Reputation: 1930
Missing 2nd parameter:
$db1 = mysql_connect($dbhost, $dbuser, $dbpass);
$rv = mysql_select_db($dbname1, $db1);
Upvotes: 2