Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

I have to use CURL to connect to my remote database

Never used CURL before. Is this even possible?



5:05 pm on Jun 24, 2008 (gmt 0)

5+ Year Member

I'm trying to insert some data into an MySQL database using PHP, however, my hosting company dosn't allow this.

I used a simple script:

mysql_query("INSERT INTO table (value1) VALUES ($value)");

I contacted my server and they said:

"If you you want to make any outbound remote connections you will need to use our proxy server. Below is a PHP script that uses CURL to connect securely to a remote system (http://www.paypal.com), obtain data from that system and then creates a Web page based on that data.

if (isset($_GET["site"])) { $URL = $_GET["site"]; }
$ch = curl_init();
echo "URL = $URL <br>n";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt ($ch, CURLOPT_URL, $URL);
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$result = curl_exec ($ch);
echo "<hr><br>n";
echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
echo "<hr><br>n";
curl_close ($ch);
print "result - $result";
echo "<hr><br>n";"

How do I change this so I can make a simple database connect and insert? Or is this even the right direction?



4:06 pm on Jun 25, 2008 (gmt 0)

10+ Year Member

still alone? here are using curl [webmasterworld.com...]


2:52 am on Jun 26, 2008 (gmt 0)

5+ Year Member

Thank you for your reply.

Right now I'm just wondering if mysql connects or inserts can even take place through cURL.

It seems like cURL is just used for getting data from another page, but can mysql queries take place over it? Or did the help desk just send me searching for a red herring?


1:01 pm on Jun 26, 2008 (gmt 0)

10+ Year Member

The CURL is for talking to remote HTTP services on port 80 and can work through a HTTP proxy.

Your mysql client is trying to talk to a mysql database running on a remote port 3306 (or 3333, or whatever port is configured over there, but you surely have checked this).

Different thing, different ports, different protocol, different understanding of what a proxy is and how it works, apples and oranges.

Kind regards,


2:03 pm on Jun 26, 2008 (gmt 0)

5+ Year Member

I believe that mysql_connect() can accept a remote host as an argument, however--try looking into that.


3:40 pm on Jun 26, 2008 (gmt 0)

5+ Year Member


My understanding now is that CURL is the wrong way to go about this. Right?

Looking at the mysql_connect function on php.net, it states for the server parameter:

"The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost.

If the PHP directive mysql.default_host is undefined (default), then the default value is 'localhost:3306'. In SQL safe mode, this parameter is ignored and value 'localhost:3306' is always used."

I don't fully understand all of this right now, but is this the area I would want to focus on?

Is the mysql_connect the failing part of my simple inserting script? If I were able to get the mysql_connect function rigged to connect to my remote host, would I be able to insert and disconnect just find? Or would I most likely have to play around with those aspects too?



4:14 pm on Jun 26, 2008 (gmt 0)

10+ Year Member

Ntgbl, in your original posting you wrote about connecting to a REMOTE database service running on another distant host "database.tld".

To connect to a remote database (on another box than your webserver), try this:
if the remote database is confugured to run on port 3306.

To connect to a local database (on the same box as your webserver), try this:

Your original statement

my hosting company dosn't allow this
implied to me that you have already done all checks necessary to come to this conclusion.

Is the mysql_connect the failing part of my simple inserting script?
We don't know, unless you check for this error:
if (!$mysql_connect) {
die('no connect: ' . mysql_error());
} else {
echo 'db connect OK';

Here is the manual page:

Kind regards,

[edited by: Romeo at 4:16 pm (utc) on June 26, 2008]


4:25 pm on Jun 26, 2008 (gmt 0)

5+ Year Member

mysql_connect should do everything you need.

You can determine if it's the point of failure by calling mysql_error() after every mysql action you take. This will tell you where and what the error is.


Featured Threads

Hot Threads This Week

Hot Threads This Month