I recently upgraded my PHP version on my host and I think it is causing this error. Whenever I start apache and this include file is called to access the database, apache starts generating GIGABYTES of errors. I view the log and I receive this error
PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/html/includes/database.config.php on line 22
Line 22 is
while(($c = mysql_fetch_assoc($rsetCoupons)) !== false)
I am guessing that it will generate that error on every place this is listed.
Does anyone have any idea on what could be causing this? The current PHP version is
PHP 5.3.2 (cli) (built: Jun 25 2011 08:12:19)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
(obviously I cut out the variables for the connect at the beginning of the code)
@mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD);
@mysql_select_db(MYSQL_DATABASE);
define('DOMAIN', 'MYDOMAINISTHIS.com');
$parse_version = queryFetch('SELECT version,secret FROM version ORDER BY version_id DESC LIMIT 0,1');
$VERSION = $parse_version['version'];
$SECRET = $parse_version['secret'];
$VALID_COUPONS = array();
$rsetCoupons = query('SELECT * FROM coupons ORDER BY coupon_id ASC');
while(($c = mysql_fetch_assoc($rsetCoupons)) !== false)
{
$VALID_COUPONS[$c['code']] = $c['percent'];
}
$salutations = array();
$rsetSalutations = query('SELECT * FROM salutations ORDER BY salutation_id ASC');
while(($c = mysql_fetch_assoc($rsetSalutations)) !== false)
{
$salutations[] = $c['salutation'];
}
$BASE_PRICE_QTY = array();
$UPGRADE_PRICE = array();
$rsetPrices = query('SELECT * FROM cart_prices ORDER BY qty ASC');
while(($c = mysql_fetch_assoc($rsetPrices)) !== false)
{
$BASE_PRICE_QTY[] = $c['unit_price'];
$UPGRADE_PRICE[] = $c['upgrade_price'];
}
function insert($hash, $table)
{
$fields = implode(',', array_keys($hash));
$values = implode('","', $hash);
$query = sprintf('INSERT INTO %s (%s) VALUES("%s")', $table, $fields, $values);
query($query);
}
function query($query)
{
return @mysql_query($query);
}
function queryFetch($query)
{
return @mysql_fetch_assoc(query($query));
}
function p($key, $default = '')
{
if (isset($_POST[$key]))
{
return $_POST[$key];
}
else
{
return $default;
}
}
function g($key, $default = '')
{
if (isset($_GET[$key]))
{
return $_GET[$key];
}
else
{
return $default;
}
}
$rsetCoupons is not a mysql query resource at that point in execution. Either your query is failing, or the variable is being lost somewhere.
http://php.net/mysql_fetch_assoc
I’m fairly certain you’re query is failing. You should check the return of mysql_query and if it’s false, then check mysql_error().
Also, you should not suppress errors in your mysql_connect and mysql_select_db calls. If the database connection cannot be made, you should handle that more gracefully than letting your page trod on and error on every subsequent mysql call. That may actually be what your error is. If you’re suppressing errors to hide them from users, public facing PHP sites should have display_errors set to off, but you should still be logging errors.