connor4312
05-31-2011, 06:03 PM
Hi,
So long story short, I have one page containing the following code:
function mysql_remote_query($sql, $link=""){
$ch=curl_init("seekrit url"); //Replaced for the forums
$key="password";
$post="sql=".urlencode(base64_encode(serialize($sql)))."&key=".$key;
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
$result = trim(curl_exec($ch));
if (strpos($result, 'ERROR')===false) {
$result=unserialize($result);
if ($result=='false'){
return false;
} else {
return $result;
}
} else {
die ("\n\n".$result."\n\n");
}
return $result;
}
to communicate with
<?php
if (isset($_POST['key'])){
if ($_POST['key']=="dASKmtDSosw"){
if (isset($_POST['sql'])){
mysql_connect('localhost', 'tppusr_index', 'password');
mysql_select_db('tppusr_tpp');
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");
$sqls=unserialize(base64_decode($_POST['sql']));
if (!is_array($sqls)){
$out=db_exec($sqls);
} else{
$out=array();
foreach ($sqls as $sql){
$out[]=db_exec($sql);
}
}
echo serialize($out);
mysql_close();
}
}
}
function db_exec($sql){
$result=mysql_query($sql) or die("ERROR: ".mysql_error()."\n\n".print_r($sql));
if ($result!==true){
if (mysql_num_rows($result)==0){
return "false";
} else {
$out=array();
while ($row=mysql_fetch_assoc($result)){
$out[]=$row;
}
return $out;
}
} else {
return "true";
}
}
?>
Now, that's fine, but when I tried to read a returned array using mysql_fetch_array, it yells at me saying "supplied argument is not a valid MySQL result resource" The queries themselves are correct and have worked before.
Any help?
Thanks,
Connor
So long story short, I have one page containing the following code:
function mysql_remote_query($sql, $link=""){
$ch=curl_init("seekrit url"); //Replaced for the forums
$key="password";
$post="sql=".urlencode(base64_encode(serialize($sql)))."&key=".$key;
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER ,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
$result = trim(curl_exec($ch));
if (strpos($result, 'ERROR')===false) {
$result=unserialize($result);
if ($result=='false'){
return false;
} else {
return $result;
}
} else {
die ("\n\n".$result."\n\n");
}
return $result;
}
to communicate with
<?php
if (isset($_POST['key'])){
if ($_POST['key']=="dASKmtDSosw"){
if (isset($_POST['sql'])){
mysql_connect('localhost', 'tppusr_index', 'password');
mysql_select_db('tppusr_tpp');
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");
$sqls=unserialize(base64_decode($_POST['sql']));
if (!is_array($sqls)){
$out=db_exec($sqls);
} else{
$out=array();
foreach ($sqls as $sql){
$out[]=db_exec($sql);
}
}
echo serialize($out);
mysql_close();
}
}
}
function db_exec($sql){
$result=mysql_query($sql) or die("ERROR: ".mysql_error()."\n\n".print_r($sql));
if ($result!==true){
if (mysql_num_rows($result)==0){
return "false";
} else {
$out=array();
while ($row=mysql_fetch_assoc($result)){
$out[]=$row;
}
return $out;
}
} else {
return "true";
}
}
?>
Now, that's fine, but when I tried to read a returned array using mysql_fetch_array, it yells at me saying "supplied argument is not a valid MySQL result resource" The queries themselves are correct and have worked before.
Any help?
Thanks,
Connor