简体   繁体   中英

Works on PHP, doesn't work on PHPUnit

I have a simple query which does work in a plain environment, but doesn't work on PHPUnit.

Here's the code, but I don't think it will be of any use:

$a = mysql_query("SELECT id,img FROM images");
$b = mysql_fetch_array($a);

I'm connected to the database.

The error is:

mysql_fetch_array() expects parameter 1 to be resource, boolean given.

Error is pointing to the fetch command.

The query failed. When queries fail the mysql_query() function returns false .

You should always check for errors. You should also read the documentation when your code does not work; it tells you what to look for.

$a = mysql_query("SELECT id,img FROM images");
if ($a === false) {
    die(mysql_error());
}
$b = mysql_fetch_array($a);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM