Database connection

Discussion in 'Programming' started by Namesniper, Aug 1, 2007.

  1. #1
    Hello,

    It has happened that i am in need of a small php script to execute two empty and one update commands for a particular database on my server.
    Can anyone please tell me what should be teh syntax in php script so i run it from cron daily ?
     
    Namesniper, Aug 1, 2007 IP
  2. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #2
    Your requirement is not clear. Are you using mysql?
    What is meant by empty query? What table do you want to update?
     
    it career, Aug 2, 2007 IP
  3. Namesniper

    Namesniper Well-Known Member

    Messages:
    365
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Ok,here is what i am trying to do.
    I need to create php script to run queries to one of my database,i will be runing that php script from cron.
    The script should empty two tables and also update another one.
    Lets call updating table update_1 and and tables which must be emptied update_2 and update_3
    Would be great of you could post the syntax of php script.
     
    Namesniper, Aug 2, 2007 IP
  4. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #4
    
    http://w3schools.com/php/php_mysql_update.asp
    
    Code (markup):
    This could help.
     
    it career, Aug 2, 2007 IP
  5. Namesniper

    Namesniper Well-Known Member

    Messages:
    365
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #5
    Thanks,i have tried it to update the table but it seems that there is something wrong with my code..

    <?php
    $con = mysql_connect("localhost","database_name","database_password");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }mysql_select_db("my_db", $con);

    mysql_query("update tsl_sites set hit_count=0");mysql_close($con);
    ?>


    Any suggestions?
     
    Namesniper, Aug 2, 2007 IP
  6. JZWolf

    JZWolf Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Check here:
    "www.php.net/manual/en/function.mysql-query.php"
     
    JZWolf, Aug 2, 2007 IP
  7. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #7
    I think your database name is not database_name and password is not database_password (create a database and database password first)
     
    it career, Aug 2, 2007 IP
  8. neelesh

    neelesh Peon

    Messages:
    141
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have not used cron jobs, but this is not the syntax.
     
    neelesh, Aug 4, 2007 IP
  9. AdnanAhsan

    AdnanAhsan Well-Known Member

    Messages:
    601
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #9
    i think you should create simple script for database connectivity and queries, than put it on cronjobs...
     
    AdnanAhsan, Aug 6, 2007 IP
  10. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #10
    neelesh, He is trying to get the script to work, then call it from a cron job.

    When something doesn't work, show us what the output was, e.g. an error message. I think "it career" is right about the database settings.
     
    krt, Aug 6, 2007 IP
  11. Namesniper

    Namesniper Well-Known Member

    Messages:
    365
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    118
    #11
    Thanks everyone,i have figured out correct code,the script works just perfect and there are just 11 lines of code.
     
    Namesniper, Aug 7, 2007 IP