Re: PHP Command line script

From: Date: Wed, 02 May 2007 17:43:13 +0000
Subject: Re: PHP Command line script
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-254247@lists.php.net to get a copy of this message
Greg Donald wrote:
On 5/1/07, Nathaniel Hall <lists@spider-security.net> wrote: I am attempting to run a script that will run from the command line nightly to update a field in a database. I already created a script that would access the database and insert most of the information when a webpage is visited and I had no problems with it. The command line script appears to fail on the prepare. I have echo'ed the SQL statement to the screen, copied it, and run it on the MySQL server with no problems. Any ideas? <?php
        $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
        if (mysqli_connect_errno()) {
                echo "Unable to connect to database.\n";
                exit;
        } else {
                $login = date('m\-d\-Y');
                if ($logout = $mysqli->prepare("UPDATE mydb.authlog
SET logout = ? WHERE login LIKE '$login%'")) { // <--- Will not go any further than here, even when hard coding the information.
                        $logout->bind_param("s", date('m\-d\-Y\TH\:i\:s'));
                        $logout->execute();
                        $logout->close();
                }
        }
        $mysqli->close();
?> Add full error reporting, then make sure you can see the errors, then test to see if you have the mysqli extension: error_reporting( E_ALL ); ini_set( 'display_errors', 1 ); ini_set( 'log_errors', 1 ); if( !in_array( 'mysqli', get_loaded_extensions() ) ) {
    die( 'no mysqli found' );
} I get no errors and I have verified that mysqli is loaded.
Also, why do you need to escape the dashes in the date() calls? php -r 'echo date("Y-m-d");' 2007-05-01 Habit.
-- Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA Spider Security

« previous php.general (#254247) next »