Example #1
0
 /**
  * Returns array of update SQL with default options, $source, $destination - database structures
  * @access public
  * @param string $source structure dump of database to update
  * @param string $destination structure dump of the reference database
  * @param bool $asString if true - result will be a string, otherwise - array
  * @return array|string update sql statements - in array or string (separated with ';')
  */
 public function getUpdates($source, $destination, $asString = false)
 {
     // Remove double spaces
     $source = Converter::spaces2space($source);
     $destination = Converter::spaces2space($destination);
     // Cut sql to check if structure is same
     $source_cut = strstr($source, 'AUTO_INCREMENT=', true);
     $destination_cut = strstr($source, 'AUTO_INCREMENT=', true);
     // Same structure - return nothing
     if ($source_cut == $destination_cut) {
         //            return '';
     }
     $result = $asString ? '' : [];
     $compRes = $this->compare($source, $destination);
     if (empty($compRes)) {
         return $result;
     }
     $compRes = $this->filterDiffs($compRes);
     if (empty($compRes)) {
         return $result;
     }
     $result = $this->getDiffSql($compRes);
     if ($asString) {
         $result = implode(";\r\n", $result) . ';';
     }
     return $result;
 }