Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    UK
    Posts
    90
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Converting Page string into variables so can update MySQL

    Hi,

    I have a mysql db on 1 server and a script to update the mysql db on another server (unfortunately), my server will not let me connect so i have gone down the page scraping route to add to the mysql.

    I have a simple page with infomation (after scraping) within it that i would like to send to mySQL db, but i'm not sure how to tell mysql which bits of data should go where, if i could make them variables i could add them accordingly.

    After page scrape data examples looks like this in the view source file, all fields are seperated with < >

    How can i take each <FIELD> and make it a variable in order so i can update mysql, there are 8 fields of data i wish to extract from each block from within the < >


    View Source Info looks like this

    &lt;FIELD1&gt;&lt;FIELD2&gt;&lt;FIELD3&gt;&lt;FIELD4&gt;&lt;FIELD5&gt;&lt;FIELD6&gt;&lt;FIELD7&gt;&l t;FIELD8&gt;<br/><br/>

    &lt;FIELD1&gt;&lt;FIELD2&gt;&lt;FIELD3&gt;&lt;FIELD4&gt;&lt;FIELD5&gt;&lt;FIELD6&gt;&lt;FIELD7&gt;&l t;FIELD8&gt;<br/><br/>

    &lt;FIELD1&gt;&lt;FIELD2&gt;&lt;FIELD3&gt;&lt;FIELD4&gt;&lt;FIELD5&gt;&lt;FIELD6&gt;&lt;FIELD7&gt;&l t;FIELD8&gt;<br/><br/>

    &lt;FIELD1&gt;&lt;FIELD2&gt;&lt;FIELD3&gt;&lt;FIELD4&gt;&lt;FIELD5&gt;&lt;FIELD6&gt;&lt;FIELD7&gt;&l t;FIELD8&gt;<br/><br/>

    HERE IS MY PHP PAGE SCRAPER CODE, not sure if this needS to be changed.

    Code:
    <?php
    //$url="http://domain.php";
    //$ch = curl_init();
    //curl_setopt($ch, CURLOPT_URL, $url);
    //curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    //$data = curl_exec ($ch);
    //curl_close ($ch);
    // you can do something with $data like explode(); or a preg match regex to get the exact information you need
    //echo $data;
    ?>
    Thanks In-adavance
    Jenna

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    I don't understand why you need to do this. Do you have access to both servers (and cpanel or any other control panel access to the server with the database)?
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    New Coder
    Join Date
    Oct 2009
    Location
    UK
    Posts
    90
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Hi,

    Yes i do have access to both servers and use cpanel, but everywhere i look informs me i cant update my database from a different server.

    If you could advise me how i would be grateful

    Thanks
    jenna

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    If you look for the Remote MySQL in cpanel on the server with the database, and add
    %.%.%.% to the Access Hosts list then you connect to your database putting the credentials in the connection info of your script, and specifying the IP/domain name of the server instead of localhost for the host name
    So instead of
    PHP Code:
    mysql_connect('localhost''username''password'); 
    it would be
    PHP Code:
    mysql_connect('domain.com''username''password'); 
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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