Thread: sql via cron

Results 1 to 5 of 5
  1. #1

    Default sql via cron

    Hi, I'm not sure whether this is the best section to ask about this but here we go anyway..

    I'm trying to automatically mark a range of products as out of stock, when I run this via 'Install SQL Patches' everything works great:

    Code:
    UPDATE products SET products_status = 1 WHERE products_quantity >= 3;
    UPDATE products SET products_status = 0 WHERE products_quantity <= 2;
    What I'm trying to work out is how I would go about running an SQL query via a cron job. This is how I have the command in CPanel:

    Code:
    php /home/trymarket/public_html/admin/stockupdate.php
    and this is stockupdate.php:

    PHP Code:
    // filename: stockupdate.php
    // make changes in /admin/init_includes/init_admin_auth.php
    if ($_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']) {
    define('CRON_ADMIN_USER_ID''99');
    }

    // your code to run via cron 
    // Updates stock

    $sql="UPDATE products SET products_status = 1 WHERE products_quantity >= 3";
    $sql="UPDATE products SET products_status = 0 WHERE products_quantity <= 2"
    Unfortunately this is not working and am pretty certain it's to do with the way I've set up the SQL functions in my php script. If someone could help me with this it would no-doubt also help me with another SQL query I'm hoping to run via cron job, which is along these lines for marking up product prices:

    Code:
    UPDATE products SET products_price = products_price *1.25 WHERE master_categories_id = 32;
    Any help with this would be appreciated ;-)

  2. #2

    Default Re: sql via cron

    Finally worked it out

    stockupdate.php:

    PHP Code:
    // your code to run via cron 
    // Updates stock
    <?php
    include("db.php");

    mysql_connect($dbhost$dbuser$dbpass) or die("CANNOT CONNECT TO DB-HOST");
        
    mysql_select_db($dbname) or die("DATABASE NAME PROBLEM");
        
        
    $sql "UPDATE products SET products_status = 1 WHERE products_quantity >= 3"
        
    mysql_query($sql) or die("SQL ERROR:<hr>".$sql);
        
        
    $sql "UPDATE products SET products_status = 0 WHERE products_quantity <= 2"
        
    mysql_query($sql) or die("SQL ERROR:<hr>".$sql);
        
        
    $sql "UPDATE products SET products_price = products_price *1.25 WHERE master_categories_id = 112"
        
    mysql_query($sql) or die("SQL ERROR:<hr>".$sql);
    ?>
    db.php:

    PHP Code:
    <?php
    //DATABASE
    //EDIT ONLY BETWEEN QUOTES

    $dbhost="localhost";            // YOUR HOST NAME USUALLY LOCALHOST
    $dbuser="username";     // YOUR DATA BASE USER NAME USUALLY ROOT
    $dbpass="pass";                 // YOUR DATA BASE PASSWORD
    $dbname="databasename";   // YOUR DATA BASE NAME
    ?>

  3. #3
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: sql via cron

    Code:
    php /home/trymarket/public_html/admin/stockupdate.php
    Secure your site NOW!!!
    http://www.zen-cart.com/forum/forumdisplay.php?f=134
    Zen-Venom Get Bitten

  4. #4

    Default Re: sql via cron

    It's ok Kobra I just named my admin area like that as an example, its not really called that

  5. #5
    Join Date
    Feb 2011
    Posts
    39
    Plugin Contributions
    0

    Default Re: sql via cron

    I need a similar mod to this but based on price range markup

    for example:

    £0 - £20 = 10%
    £21 - £30 = 15%
    £31 - £100 = 20%

    How would I go about defining a price range and % for each?

    Many Thanks in advance..

 

 

Similar Threads

  1. Can I run Backup MYSQL Plugin v1.4 via cron job?
    By Renz in forum General Questions
    Replies: 2
    Last Post: 23 Mar 2012, 06:25 AM
  2. Adding Mass Descriptions via SQL?
    By jsnacker in forum General Questions
    Replies: 3
    Last Post: 29 Jun 2011, 03:43 PM
  3. upload category images via sql??
    By wtashby in forum General Questions
    Replies: 14
    Last Post: 21 Aug 2010, 05:14 PM
  4. Automated Backup via CRON ??
    By Netsmurf in forum General Questions
    Replies: 4
    Last Post: 14 May 2007, 06:05 PM
  5. How do I run the stock_attribute.sql via Install SQL Patches in admin
    By vivaraquel in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 9 Apr 2007, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg