Forum Moderators: coopster
I used a simple script:
$mysql_connect=mysql_connect("database.tld","username","password");
mysql_select_db("database_name");
mysql_query("INSERT INTO table (value1) VALUES ($value)");
mysql_close($mysql_connect);
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.
$URL="https://www.paypal.com";
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_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
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?
Thanks
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,
R.
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?
Thanks
To connect to a remote database (on another box than your webserver), try this:
$mysql_connect=mysql_connect('database.tld:3306','username','password');
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:
$mysql_connect=mysql_connect('localhost','username','password');
Your original statement
my hosting company dosn't allow thisimplied 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:
Here is the manual page:
[php.net...]
Kind regards,
R.
[edited by: Romeo at 4:16 pm (utc) on June 26, 2008]