Results 1 to 10 of 10

Thread: Need help with exchange rate project involving mysql/postgresql and PHP

  1. #1
    Join Date
    Jun 2009
    Location
    Saco, ME
    Beans
    181
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Question Need help with exchange rate project involving mysql/postgresql and PHP

    What I'm trying to do: Have a PHP(or shell) script that will run daily with cron to go out to a database that holds exchange rates, get the exchange rates for the day, then insert them into a mysql(or postgresql) database.

    Where I'm stuck: I can't seem to find a database out there where you can just connect anonymously to grab exchange rates. Figures I hit a wall before I really get going

  2. #2
    Join Date
    Jan 2005
    Location
    South Africa
    Beans
    2,098
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    Not sure where your problem is. In php, you use something like
    Code:
    $dbcnx=mysql_connect("localhost","username","password");
    You don't want the username and password, I assume. Question is why not? What will be the difference between an anonymous user and a 'dummy' that you use to insert/update the exchange rates.
    If you don't make backups of your important data, your data is obviously not important to you.

  3. #3
    Join Date
    Jul 2009
    Beans
    18
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    Instead of connecting to a database, how about a site that lists exchange rates? Google Finance's main page has a listing of some major currencies: http://www.google.com/finance

    You could use wget from your shell script, and parse the data that you are looking for. You would just have to keep an eye on this script because if Google (or whatever financial site you use) changes, you may have to modify your script. Hope this helps.

  4. #4
    Join Date
    Jun 2009
    Location
    Saco, ME
    Beans
    181
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    To Wim: I know how to do a database connection via PHP. My issue is who has a database that I can access either with a generic user or no user/password at all.

    --------------------
    My trepidation with parsing a web page is just as you mentioned, sites change, and I don't want to have to modify the script every time the site changes. Another contributing factor is that I need exchange rates for some really odd currencies, so I was hoping to find one gigantic database with all(most) currencies. I'm not really concerned with past exchange rates, but I want to be able to grab them on a daily basis and insert them into my database.

    P.S. Thanks for the replies!

  5. #5
    Join Date
    Jan 2005
    Location
    South Africa
    Beans
    2,098
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    Sorry, that was not quite clear to me.
    If you don't make backups of your important data, your data is obviously not important to you.

  6. #6
    Join Date
    Apr 2009
    Beans
    130

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    It's extremely unlikely that someone is going to allow direct database access to such information (at least for free).

    You might be able to find a site that offers an API instead, which returns the data in XML or whatever format they use, suitable for automatic parsing.

    Quick google search brings up http://finance.xaviermedia.com/, which lets you get it via XML: http://api.finance.xaviermedia.com/api/latest.xml (your browser will probably format that nicely, use view source to see what you'd actually get in your php script).

    This works much better than screen scraping a website, since it is immune to layout changes, as long as they keep the API available.

  7. #7
    Join Date
    Jun 2009
    Location
    Saco, ME
    Beans
    181
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    Thanks for the input. The project lead and I decided that what we're trying to do is much more effort than just a manual copy and paste. TOPIC SOLVED/CLOSED

  8. #8
    Join Date
    Apr 2009
    Beans
    130

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    Personally I would consider using that API I linked to be the least effort way - might take an hour to setup, but you only have to do it once.

    But to each his own...

  9. #9
    Join Date
    Jun 2009
    Location
    Saco, ME
    Beans
    181
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    I think I'm going to give it a shot anyway on my own time. I like having things automated, even if it takes some work. I'll probably have more questions when it comes time to do the actual scripting. On that subject, do you know of any good tutorials for shell scripting?

  10. #10
    Join Date
    Jun 2009
    Location
    Saco, ME
    Beans
    181
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Need help with exchange rate project involving mysql/postgresql and PHP

    ~Bump~

Tags for this Thread

Bookmarks

Posting Permissions

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