#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    How to pull api array into database?


    I am not that great with PHP so I need some help pulling an array from an API into a MYSQL database. I guess the problem is two-fold:

    1. How should the database tables be setup?

    2. What is the php to actually perform the insert? I have tried cutting and pasting various code from around the internet but I always end up with errors.

    Here is what is returned from the API:


    Code:
       Array
        (
        [success] => 1
        [return] => Array
            (
                [0] => Array
                    (
                        [a] => 22016931
                        [b] => 2014-02-07 15:35:17
                        [c] => 0.00000160
                        [d] => 10011.32572730
                        [e] => 0.01581789
                        [f] => Yes
                    )
    
                [1] => Array
                    (
                        [a] => 22016912
                        [b] => 2014-02-07 15:34:56
                        [c] => 0.00000159
                        [d] => 7100.05070406
                        [e] => 0.01121808
                        [f] => Yes
                    )
    
                [2] => Array
                    (
                        [a] => 22016911
                        [b] => 2014-02-07 15:34:56
                        [c] => 0.00000158
                        [d] => 13089.15960294
                        [e] => 0.02068087
                        [f] => No
                    )
    
    
            )
    
        )
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by jbass350z
    1. How should the database tables be setup?
    How are we supposed to tell you that without any knowledge about your data?

    Your example shows a bunch of records with 6 values each, but what those mean and how the records might be related is totally unclear.



    Originally Posted by jbass350z
    2. What is the php to actually perform the insert? I have tried cutting and pasting various code from around the internet but I always end up with errors.
    Do not copypaste random code from the Internet, especially if you plan to upload your application to a server.

    The majority of free-floating PHP code is garbage. If you're lucky, it will simply not run. If you have less luck, you'll end up with plenty of security vulnerabilities waiting to be exploited by the next best script kiddie.

    Learn PHP. And then write the code yourself. To give you a start: How to access a MySQL database with PHP. But again: Don't just copypaste the code.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo