php - mysql_fetch_assoc() expects parameter 1 to be resource, null given in -


i follow topic because have same problem ( can't use command shell, edit file host ) -> change value after 24 hours

first run sql

create table `php_cron` (   `id` int(11) unsigned not null auto_increment,   `last_ts` datetime default null,   primary key (`id`) );  insert `php_cron` (`id`, `last_ts`) values (1,'2012-08-10 00:00:00'); 

and code

$res1 = mysql_query("select time_to_sec(timediff(now(), last_ts)) tdif php_cron id=1"); $dif = mysql_fetch_assoc($dif['tdif']);  if ($dif >= 86400) { //24h      //following code run once every 24h      //update user's page rank     $sql2 = "update logs_limitbandwidthtoday set bandwidthtoday = 0";      mysql_query($sql2);      $sql23 = "update logs_limitlinktoday set limitlink = 0";      mysql_query($sql23);      $sql24 = "update logs_limitvipbw set bandwidthtoday = 0";      mysql_query($sql24);      $sql25 = "update logs_limitviplink set limitlink = 0";      mysql_query($sql25);      $sql26 = "update account_vip set alltime = alltime - 1 alltime > 0";      mysql_query($sql26);      //update last execution time     $sql3 = "update php_cron set last_ts = now() id=1";     mysql_query($sql3);  } 

error -> php warning: mysql_fetch_assoc() expects parameter 1 resource, null given in /.... on line 2

and not sure code still work or not, please give me answer question. thank !

ok should solve problem

$dif = mysql_fetch_assoc($res1);  $dif1 = $dif['tdif'];  if ($dif1 >= 86400) { 

but since mysql_* outdated , removed php 7.0 updated code should this

$res1 = mysqli_query($con,"select time_to_sec(timediff(now(), last_ts)) tdif php_cron id=1"); $dif = mysqli_fetch_assoc($res1);  $dif1 = $dif['tdif'];  if ($dif1 >= 86400) {      //following code run once every 24h      //update user's page rank     $sql2 = "update logs_limitbandwidthtoday set bandwidthtoday = 0";      mysqli_query($con,$sql2);      $sql23 = "update logs_limitlinktoday set limitlink = 0";      mysqli_query($sql23);      $sql24 = "update logs_limitvipbw set bandwidthtoday = 0";      mysqli_query($con,$sql24);      $sql25 = "update logs_limitviplink set limitlink = 0";      mysqli_query($con,$sql25);      $sql26 = "update account_vip set alltime = alltime - 1 alltime > 0";      mysqli_query($con,$sql26);      //update last execution time     $sql3 = "update php_cron set last_ts = now() id=1";     mysqli_query($con,$sql3);  } 

where $con connection sting make database

$server='localhost';//your host name $user_name='root';//your mysql user name root default $password='';//your mysql password blank default $database='db';//your database name  $con=mysqli_connect($server,$user_name,$password,$database); 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -