Reputation: 4480
When I run the script below on my browser all that prints out is 0: If I erase MySQL_errno I get nothing. How would I get a more detailed error?
<?php
$link = mysql_connect("192...", "root", "");
mysql_select_db("visitors_tables");
echo mysql_errno($link) . ": " . mysql_error($link). "\n";
echo mysql_error();
$query = "SELECT * FROM visitors";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result))
{
foreach ($line as $value)
{
print "$value\n";
}
}
mysql_close($link);
?>
Upvotes: 0
Views: 65
Reputation: 746
try using the below code. & insert the column_name you want to fetch at echo $line['column_name']
<?php
$link = mysql_connect("192...", "root", "");
if($link){
mysql_select_db("visitors_tables");
}
$query = "SELECT * FROM visitors";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result)){
echo $line['column_name']
}
mysql_close($link);
?>
Upvotes: 0
Reputation: 10638
You aren't getting an error. But since mysql_errno()
and mysql_error()
is in no condition, it gets echoed anyway.
You can do it like this:
function showError($link) {
return mysql_errno($link).': '.mysql_error($link);
}
$link = mysql_connect("192...", "root", "") or die(showError($link));
mysql_select_db("visitors_tables") or die(showError($link));
//etc.
$result = mysql_query($query) or die(showError($link));
or ...;
only gets called when there actually is an error.
Upvotes: 2