开发者

Connected to database but information returns as bool

mysql_select_db('fireworks', $conn);

$ask = "SELECT * FROM name";
$result = mysql_query($ask, $conn) or die();
while ($info = mysql_fetch_assoc($result));
{
    var_dump($info);
    if (is_array($result)) {
        foreach ($info as $group) {
            print $group;
        } //end foreach
    } else {
        print "fail..";
    }//end debug
} //end while

I checked with phpmyadmin and the database fireworks CLEARLY has a table name开发者_如何学Pythond 'name' in it. When I use var_dump it shows bool(false). I heard that mysql_fetch_assoc is suppose to return false only if there is no more values left to print?

Edit: Sorry I should have included the full code:

$conn = mysql_connect("localhost", "root") or die(mysql_error());
if ($conn)
{
    print "<h1>CONNECTED!!!!</h1>";
}//end conn

Yes, I have information listed in the table, I checked the name of everything:

ID  firstName lastName
1   uraz      The pig
2   Billy     Henson
3   Jean      Jerk
4   Fat       Jerk


Your code has a logical syntax error:

while ($info = mysql_fetch_assoc($result));

Currently this causes it to loop through all the rows, and when it's done you're left with the last value (false).

You should have:

while ($info = mysql_fetch_assoc($result))


You don't seem to have actually connected to a mysql database, unless you've left that code off. Also, if your table is empty or there are no more rows to fetch, mysql_fetch_assoc will return false. So, double-check that you're selecting the data properly.

Does your mysql user have SELECT permission? Is the password correct? Is fireworks the correct database name? Some web hosts will append your account username as a prefix to all databases, so maybe yours is bnynn_fireworks (except, with your account username.)

I'm not sure how this is actually possible though that you're getting false, it shouldn't even enter the while loop.


You send the query, retrieve the first row and make a weird check:

$result = mysql_query($ask, $conn) or die();
while ($info = mysql_fetch_assoc($result));
{
var_dump($info);
if (is_array($result)) // <--- :-?
{
foreach ($info as $group)
{print $group;} //end foreach
}else{
print "fail..";
}//end debug
} /

The mysql_query() function returns a resource or a boolean FALSE, but it will never be an array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜