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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.