Jump to content

Problems using URL in cURL when grabbed from mysql table


soma56

Recommended Posts

I wasn't too sure if this should be in the MySQL help section so please (admin/mods) feel free to move this if you feel it's necessary.

 

I'm attempting to connect to a URL through cURL that is being grabbed from a mysql table.

 

The url within the table is:

 

http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html"

 

When I plug this into firefox it works.

 

When using it through cURL directly (see below) it works.

 

$url = "http://es-us.noticias.yahoo.com/ue-podr%C3%ADa-revisar-veda-crudo-ir%C3%A1n-en-pr%C3%B3ximos-124018543.html";

   // create a new curl resource
   $ch = curl_init();
   
   // set URL to download
   curl_setopt($ch, CURLOPT_URL, $url);


   // user agent:
   curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

   // remove header? 0 = yes, 1 = no
   curl_setopt($ch, CURLOPT_HEADER, 0);

   // should curl return or print the data? true = return, false = print
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   
// timeout in seconds
   curl_setopt($ch, CURLOPT_TIMEOUT, 60);
   
   // download the given URL, and return output
   $page = curl_exec($ch);

 

However, when I grab the url from a table within mysql it does not work and no curl error (or any error for that matter) is returned.

 

$get_url_links = "SELECT * FROM tabe";
$url_link = mysql_query($get_url_links);

$row = mysql_fetch_array($url_link);
$url = $row['link']."<br />";

 

I'm suspecting this is some kind of encoding issue. I've tried

 

$url = mysql_real_escape_string($url); --- before entering it into the table

$url = mysql_real_escape_string($url); --- before calling cURL

mysql_query("set names 'utf8'"); --- before inserting the url into the table

 

I've also set the column table type to 'text'.

 

Suggestions appreciated. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.