Jump to content

mabseyuk

New Members
  • Posts

    2
  • Joined

  • Last visited

mabseyuk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, Here is the old code. What does it do, it takes a MySql Command from an external 3rd Party App, and gets the results from the database, and Pulls in the results. So the POST Query is effectively the MySql Command to pull records from the database. This is a MySql Wrapper effectively. <?php header("Content-type: text/html; charset=utf-8"); define('DB_HOST','myhost'); define('DB_USER','myusername'); define('DB_PASS','mypassword'); define('DB_NAME','mydb'); define('PASSWORD','connectionpassword'); $db = mysql_connect(DB_HOST,DB_USER,DB_PASS) or die('<?xml version="1.0"?><error><![CDATA[' . mysql_error(). ']]></error>'); mysql_select_db(DB_NAME, $db) or die('<?xml version="1.0"?><error><![CDATA[' . mysql_error(). ']]></error>'); mysql_query("SET NAMES 'utf8'") or die('<?xml version="1.0"?><error><![CDATA[' . mysql_error(). ']]></error>'); ; mysql_query("SET SESSION SQL_BIG_SELECTS=1;") or die('<?xml version="1.0"?><error><![CDATA[' . mysql_error(). ']]></error>'); if ($_GET["password"]!=PASSWORD){exit('<?xml version="1.0"?><error><![CDATA[Password is incorrect!]]></error>');} $xmlP = new Queries(str_replace('\\"','"',str_replace("\\'","'",urldecode($_POST['query'])))); $xmlP->parseQueries(); foreach($xmlP->queries as $k=>$v) { $queries = split("--GO;--",$v); foreach($queries as $q){ $result = mysql_query($q); } if($xmlP->request == 'RETURN'){ $xmlP->select($result, $k); } else { $xmlP->exec($result, $k); } } $xmlP->prepareReturn(); echo('<?xml version="1.0"?>'.$xmlP->xmlReturn); class Queries { private $xml; private $xmlQueries; public $request; public $queries = array(); public $ids = array(); public $return = array(); public $xmlReturn = array(); public function __construct($xml) { $this->xml = $xml; } public function parseQueries() { preg_match('/<queries type="([^"]+)">(.+)<\/queries>/s', $this->xml, $m); $this->request = $m[1]; $this->xmlQueries = $m[2]; preg_match_all('/<query id="([^"]+)">(.+?)<\/query>/s', $this->xmlQueries, $m); $this->ids = $m[1]; $this->queries = $m[2]; } public function select($res, $k) { if(!mysql_num_rows($res) && mysql_error()!=""){ $this->return[$this->ids[$k]]['status'] = 'ERROR'; $this->return[$this->ids[$k]]['error'] = mysql_error(); } else { $this->return[$this->ids[$k]]['status'] = 'OK'; while($row = mysql_fetch_array($res)) { foreach($row as $key=>$val) { if(preg_match('/^[0-9]+$/',$key)) unset($row[$key]); } $this->return[$this->ids[$k]][] = $row; } } } public function exec($res, $k) { if($res || mysql_error()==""){ $this->return[$this->ids[$k]]['status'] = 'OK'; } else { $this->return[$this->ids[$k]]['status'] = 'ERROR'; $this->return[$this->ids[$k]]['error'] = mysql_error(); } } public function prepareReturn() { $this->xmlReturn = '<resultset>'; foreach($this->return as $k=>$v) { $this->xmlReturn.= '<return id="'.$k.'" status="'.$v['status'].'">'; if($v['status'] == 'ERROR'){ $this->xmlReturn.= '<errormessage>'.$v['error'].'</errormessage>'; } else { foreach($v as $key=>$val) { if(preg_match('/^[0-9]+$/',$key)){ $this->xmlReturn.= '<row>'; foreach($val as $recId=>$recValue) { $this->xmlReturn.= "<$recId><![CDATA[$recValue]]></$recId>"; } $this->xmlReturn.= '</row>'; } } } $this->xmlReturn.= '</return>'; } $this->xmlReturn.= '</resultset>'; } } ?> And here is my attempt to start converting it, apologies, but its been 15 years since I've been actively coding: <?php header("Content-type: text/html; charset=utf-8"); define('DB_HOST','myhost'); define('DB_USER','myusername'); define('DB_PASS','mypassword'); define('DB_NAME','mydb'); define('PASSWORD','connectionpassword'); $db = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die('<?xml version="1.0"?><error><![CDATA[' . mysqli_error(). ']]></error>'); mysqli_set_charset($db, 'utf8'); mysqli_select_db($db, DB_NAME) or die('<?xml version="1.0"?><error><![CDATA[' . mysqli_error(). ']]></error>'); if ($_GET["password"]!=PASSWORD){exit('<?xml version="1.0"?><error><![CDATA[Password is incorrect!]]></error>');} $xmlP = new Queries(str_replace('\\"','"',str_replace("\\'","'",urldecode($_POST['query'])))); $xmlP->parseQueries(); foreach($xmlP->queries as $k=>$v) { $queries = explode("--GO;--",$v); foreach($queries as $q){ $result = mysqli_query($q); } if($xmlP->request == 'RETURN'){ $xmlP->select($result, $k); } else { $xmlP->exec($result, $k); } } $xmlP->prepareReturn(); echo('<?xml version="1.0"?>'.$xmlP->xmlReturn); class Queries { private $xml; private $xmlQueries; public $request; public $queries = array(); public $ids = array(); public $return = array(); public $xmlReturn = array(); public function __construct($xml) { $this->xml = $xml; } public function parseQueries() { preg_match('/<queries type="([^"]+)">(.+)<\/queries>/s', $this->xml, $m); $this->request = $m[1]; $this->xmlQueries = $m[2]; preg_match_all('/<query id="([^"]+)">(.+?)<\/query>/s', $this->xmlQueries, $m); $this->ids = $m[1]; $this->queries = $m[2]; } public function select($res, $k) { if(!mysqli_num_rows($res) && mysqli_error()!=""){ $this->return[$this->ids[$k]]['status'] = 'ERROR'; $this->return[$this->ids[$k]]['error'] = mysqli_error(); } else { $this->return[$this->ids[$k]]['status'] = 'OK'; while($row = mysqli_fetch_array($res)) { foreach($row as $key=>$val) { if(preg_match('/^[0-9]+$/',$key)) unset($row[$key]); } $this->return[$this->ids[$k]][] = $row; } } } public function exec($res, $k) { if($res || mysqli_error()==""){ $this->return[$this->ids[$k]]['status'] = 'OK'; } else { $this->return[$this->ids[$k]]['status'] = 'ERROR'; $this->return[$this->ids[$k]]['error'] = mysqli_error(); } } public function prepareReturn() { $this->xmlReturn = '<resultset>'; foreach($this->return as $k=>$v) { $this->xmlReturn.= '<return id="'.$k.'" status="'.$v['status'].'">'; if($v['status'] == 'ERROR'){ $this->xmlReturn.= '<errormessage>'.$v['error'].'</errormessage>'; } else { foreach($v as $key=>$val) { if(preg_match('/^[0-9]+$/',$key)){ $this->xmlReturn.= '<row>'; foreach($val as $recId=>$recValue) { $this->xmlReturn.= "<$recId><![CDATA[$recValue]]></$recId>"; } $this->xmlReturn.= '</row>'; } } } $this->xmlReturn.= '</return>'; } $this->xmlReturn.= '</resultset>'; } } ?> Any Help Appreciated. Thanks Mabs
  2. Can anyone recommend where I can pay for someone to convert a small PHP 5 Script Please to Make it PHP 7 compatible. I gave it a go myself, but simply don't have the knowledge for it. It's a 100 Line Script, and basically its used to Pull Orders from a MYSql Database and import them into a 3rd Party Order Management System I've changed the MySql Parts so it connects to the database fine now, but there are a couple of functions in the script, which don't work: split ----> I tried changing this to explode and preg_split, but the script is still chucking up errors, here is an example below: $queries = split("--GO;--",$v); I haven't coded in 15 years now, and 15 years ago would have ate this up and just fixed it, but my brain just isn't working with scripting anymore. Typical error I'm getting is Got error 'PHP message: PHP Warning: explode(): Unknown modifier 'G' in on line 26 Mabs
×
×
  • 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.