开发者

Odd mysql_fetch_array behavior

开发者 https://www.devze.com 2023-03-26 02:16 出处:网络
Here are my two offending lines from a reused function: //snip $req = mysql_query($sql,$db) or die(db_query_error($sql,mysql_error()));

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:

  • $d开发者_开发问答ata 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.


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

0

精彩评论

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

关注公众号