mabseyuk Posted May 7, 2022 Share Posted May 7, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314766-php-5-to-7-script/ Share on other sites More sharing options...
Barand Posted May 7, 2022 Share Posted May 7, 2022 Search result: Quote What does Unkown modifier g mean in PHP? Unkown modifier 'g' " often indicates a regex that was copied verbatimly from JavaScript or Perl. PHP doesn't use the /g global flag. Quote Link to comment https://forums.phpfreaks.com/topic/314766-php-5-to-7-script/#findComment-1596009 Share on other sites More sharing options...
ginerjm Posted May 7, 2022 Share Posted May 7, 2022 100 line script? Why don't you post it here? Quote Link to comment https://forums.phpfreaks.com/topic/314766-php-5-to-7-script/#findComment-1596012 Share on other sites More sharing options...
mabseyuk Posted May 15, 2022 Author Share Posted May 15, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314766-php-5-to-7-script/#findComment-1596253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.