I know there are mysql results but nevery any in php

I have a query that never returns any results or errors. When I run the sql directly through phpmyadmin the results come back fine.

just trying to dump row right now to see whats coming back

<?php
$link
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!
$link) {
    die(
'Could not connect: ' . mysql_error());
}

$sql = "SELECT ProductID,Name FROM products WHERE ProductID > 5 ORDER BY ProductID DESC";
$query = mysql_query($sql);
while (
$row = mysql_fetch_object($query)){
var_dump($row);
}
?>

never returns a single value. If I place a little text output around the vardump still comes out with nothing.

No votes yet

Replies

remember to select db

Did you remember to select the database?

mysql_select_db($database_name, $link);

Also one way to help debug query errors is to place this after any mysql query

echo mysql_error($link);

Often if queries fail because of some sort of mysql error your php will just go on fine.

Make sure you remove the error reporting before going live as it often contains information you do not want printed to random visitors.

Your rating: None

Post new comment

 
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><code>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.