Link to home
Start Free TrialLog in
Avatar of Dan560
Dan560Flag for United Kingdom of Great Britain and Northern Ireland

asked on

mysql_fetch_object(): supplied argument is not a valid MySQL re sult resource

Hi,

Can someone help me me with script below. I am trying to import values from one table to another, however I am getting the following error message. I am running mysql 4.1

<br />
<b>Warning</b>:  mysql_fetch_object(): supplied argument is not a valid MySQL re
sult resource in <b>D:\monitor\log_licence_usage.php</b> on line <b>16</b><br />


 
<?
// connect to db
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make sw_systemdb the current db
$db_selected = mysql_select_db('swdata', $link);
if (!$db_selected) {
die ('Can\'t use swdata : ' . mysql_error());
}
$webcount=0;
$clientcount=0;
$datetime = mktime();
$res = mysql_query("select analystname,connectionid from sw_systemdb.swsessions");
while ($data = mysql_fetch_object($res)) {
$connid = $data->connectionid;
settype($connid, "integer");
if ($connid<1){
$webcount++;
} else
{ $clientcount++;}
}
$Update = "insert into licenselog values ($datetime,$webcount,$clientcount)";
if (!mysql_query($Update)){
die ('Can\'t update swsessions with'.$Update.' : ' . mysql_error());
}
else {
echo('Command '.$Update.' performed');
}
mysql_close($link);
?>

Open in new window

SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mysql_query() provides a return value.  Your script must test it to see if it is a resource or FALSE.  Whether or not mysql_query() worked can only be determined by testing its return value.  mysql_num_rows() is not the appropriate test, since a query may have worked perfectly but found no matching results.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial