FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


cURL to MySQL





Gushe
Hello all.

I was trying to learn a little about cURL.

So; here is the standard script to retrieve another page's source and save it in a text file:
Code:
<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>


Now, would it be possible to write this source to a MySQL database instead of a text file? since I need to be able let multiple users do somthing similar at the same time; text files wouldn't be able to handle that.

I only need 2 collumn's; Id & Source


Thanx in Advance;
~ GuShe
rvec
add this:
Code:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

and instead of curl_exec($ch); do this:
Code:
$source = curl_exec($ch);

I think you can get it from there Smile
Gushe
So we simply get the source into a String? that would of course be even better Very Happy

thanx mate! Wink
rvec
yeah $source will contain the whole source. and you can remove the CURLOPT_HEADER line because the value you set is the default one Wink
Also when not writing to the file you can remove CURLOPT_FILE and the fopen function, so it will be nice and clean Smile
Gushe
Just Perfect. Smile

thanx mate! Wink
Related topics
mysql connection question
php admin and mysql admin console
Mysql And PHP HELP PLZ
Do you use a CMS script?
Question about MySQL!
PHP, MySQL...
PHP Book (Php and Mysql for Dynamic Web Sites)
few mysql questions
E-Cards with PHP & MySQL
HTTP AUTH with PHP and mySQL
Build an online dictionary by PHP/MySQL
Make search engine With PHP and mySQL, for your site
PHP without mySQL
Multiple versions of PHP/MySQL
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.