views:

76

answers:

2

I am working on a project where I use mysql_fetch_assoc to return an associative array.

However, I am puzzled as to why it would return TRUE

I have looked at the PHP manual page, and the only boolean value it should be returning is FALSE, and then only on a fail.

Although I am using a custom set of abstraction classes, it is basically doing this:

$result = mysql_query("SELECT * FROM table WHERE filename = 'test1.jpg'");
var_dump(mysql_fetch_assoc($result)); // bool(true)

Does anyone know why it would be returning TRUE instead of an array?

Update

Well, after trying a few things, I've determined its my library, as running the above code returns an associative array. I don't know why exactly it was returning TRUE, but for now, I am going to stop making things more complicated than they have to be (a problem of mine) and just use mysqli (thanks for the tip, Michael) instead of my own ActiveRecord classes, which apparently don't work.

Thanks!

A: 

Have you tried:

print_r (mysql_fetch_assoc($result));

It may give what you are looking for.

Oh, and silly me, var_dump () returns nothing, it directly outputs its findings like print_r ().

Meep3D
just returns `1`
Austin Hyde
What does mysql_num_rows() say? And what happens if you put the MySQL query into the db directly?
Meep3D
+1  A: 

Start using mysqli_query mysqli_fetch_assoc, . The old version is soon to be outdated - the new one is better anyways.

Michael
"soon to be outdated - the new one is better anyways", the new one would be pdo then because there was a discussion to move _all_ non-pdo db extensions from the core to pecl. But this was postponed anyways; "current" snapshots of php 6 contain both php_mysql and php_mysqli
VolkerK
@ VolkerK, good point - I'm getting outdated as well :)
Michael