1

Here are my two offending lines from a reused function:

//snip
$req = mysql_query($sql,$db) or die(db_query_error($sql,mysql_error()));
//Breakpoint A
$data = mysql_fetch_array($req);
//Breakpoint B
//snip

At Breakpoint A:

  • $req is a valid ressource
  • $db is a valid ressource
  • $sql is valid and when ran against the database will return the expected value, a simple string
  • No errors are thrown

At Breakpoint B:

  • $data should be an array with index 0 being a string with an associative named "get" that has the same string

The problem is that on this page, EVERY query works except one. For the query that doesn't work, when the SQL is ran through manually, it works and returns the proper value. I have queries running before and after this call that work properly.

  • If I do count($data), I get 1.
  • If I do echo "-".$data."-", I get "--".
  • If I do echo $data[0], blank
  • If I do echo $data[1], blank (shouldn't this create an error?)

Edit #1 - print_r, in our custom debug function, was being used. - var_dump of $data shows that it's "bool(false)". Something is wrong with either the $db or $sql variables.

Edit #2 This issue has nothing to do with MySQL. It had something to do with our publication process and where the data was located during this process.

2
  • Why don't you put the query in question..in your question? Commented Aug 6, 2011 at 0:42
  • @Shredder: the query isn't the issue as it resolves fine when ran against the db. It's the fact that $data is blank when it shouldn't be. Commented Aug 6, 2011 at 0:47

1 Answer 1

2

you can try

 var_dump($data);

also try to change

mysql_fetch_array();

to

mysql_fetch_assoc();

or to

mysql_fetch_row();

if you use numeral indexes.

I think these tests will you give your answer

Sign up to request clarification or add additional context in comments.

2 Comments

I'm fairly sure I have tried the var_dump and it was just, blank. Well, I'm assuming that our custom debug() function uses this. Also, I'm not sure if I can change to _fetch_assoc or _fetch_row. The existing codebase uses this function everywhere and I'm not sure the impacts of just using an index or an association.
I double checked and our custom debug function actually uses print_r. I will be trying var_dump to see if I get anything different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.