Search code examples
mysqlphp4

Change all values in a column mysql php 4.4.9


I have seen multiple posts saying that to update all rows in a column you use

UPDATE Table
SET Column= 'New Value',

but it doesn't seem to work for me. Here is my code:

<?php
$host_name = '';
$database = '';
$user_name = '';
$password = '';

$connect = mysql_connect($host_name, $user_name, $password, $database);
if (mysql_errno()) {
    die('Failed to connect to MySQL: '.mysql_error().'');
} else {

    $sql = "update Data set Requests = '500' ";

    if (mysql_query($connect, $sql)) {
        echo 'it worked';
    } else {
        echo 'nope';
    }
    mysql_close();
}
?>

I am trying to create a cron job that changes all the values in a column to 500 every 24 hrs. This has to be done through SSH, and my hosting provider only has php 4.4.9 in the shell. So I cannot use mysqli, only mysql to connect to the database, and it doesn't seem to work.

Any help appreciated. Thanks


Solution

  • mysql_connect() does not support $database argument, please call mysql_select_db() while the database connection was created.

    The other solution is change your SQL statement as following :

    $sql = "update $database.Data set Requests = '500'";
    

    BTW, mysql_connect() returns false if failed, I recommend you to check if $connect is false instead of call mysql_errno().