...

View Full Version : Converting Page string into variables so can update MySQL



mobimad
02-15-2010, 05:35 PM
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;&lt;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;&lt;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;&lt;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;&lt;FIELD8&gt;<br/><br/>

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



<?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

JAY6390
02-15-2010, 06:14 PM
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)?

mobimad
02-15-2010, 06:44 PM
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

JAY6390
02-15-2010, 07:06 PM
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

mysql_connect('localhost', 'username', 'password');
it would be

mysql_connect('domain.com', 'username', 'password');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum