0

I've been running a cronjob MySQL script that was working great but became deprecated and won't work anymore. I've taken a number of stabs at updating to mysqli, I can get an echo result in the logs of "ok!" but the actual query doesn't get run anymore.

This renders the cronjob moot as the main objective is to select the table 'h2lb9_users' and update the column 'block' to 0 for all rows. I'm doing this as a favor to a friend so your assistance is greatly appreciated.

NEW ATTEMPT:
<?php
$username="HERE";
$password="HERE";
$dbname="HERE";
$dbhost="localhost";
$query="update h2lb9_users set 'block' = 0";
$connection = mysqli_connect($dbhost,$dbname,$username,$password);
mysqli_select_db($connection,"I write out dbname here");
mysqli_query($query);
mysqli_close();
echo strftime('%c')." ok!";
?> 

This was the old code that was working:

OLD WAS WORKING:
<?php
$username="HERE";
$password="HERE";
$dbname="HERE";
$dbhost="localhost";
$query="update h2lb9_users set `block` = 0";
mysql_connect($dbhost,$username,$password);
@mysql_select_db($dbname) or die(strftime('%c')." Unable to select database");
mysql_query($query);
mysql_close();
echo strftime('%c')." ok!";
?>
Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

0

there are some errors in your bew script.

In your update state3ment you have to use again backticks single quote are for Strings

Then the part of selcting the database is not necessary you do this already in your connect string

The connect string has to have the correct order

And last you send mysqli commands always add the connection.

<?php
    $username="HERE";
    $password="HERE";
    $dbname="HERE";
    $dbhost="localhost";
    $query="update h2lb9_users set `block`  = 0";
    $connection = mysqli_connect($dbhost,$username,$password,$dbname);
    mysqli_query($connection,$query);
    mysqli_close($connection);
    echo strftime('%c')." ok!";
?> 
nbk
  • 45,398
  • 8
  • 30
  • 47