Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First at all thanks for this topic. This saved a lot of time for me :) And let me to make little fix for your code. Sometimes if TRIGGERS or PROCEDURES is in dump file, it is not enough to examine the ; delimiters. In this case may be DELIMITER [something] in sql code, to say that the statement will not end with ; but [something]. For example a section in xxx.sql:</p> <pre><code> DELIMITER // CREATE TRIGGER `mytrigger` BEFORE INSERT ON `mytable` FOR EACH ROW BEGIN SET NEW.`create_time` = NOW(); END // DELIMITER ; </code></pre> <p>So first need to have a falg, to detect, that query does not ends with ; And delete the unqanted query chunks, because the mysql_query does not need delimiter (the delimiter is the end of string) so mysql_query need someting like this:</p> <pre><code> CREATE TRIGGER `mytrigger` BEFORE INSERT ON `mytable` FOR EACH ROW BEGIN SET NEW.`create_time` = NOW(); END; </code></pre> <p>So a little work and here is the fixed code:</p> <pre><code> function SplitSQL($file, $delimiter = ';') { set_time_limit(0); $matches = array(); $otherDelimiter = false; if (is_file($file) === true) { $file = fopen($file, 'r'); if (is_resource($file) === true) { $query = array(); while (feof($file) === false) { $query[] = fgets($file); if (preg_match('~' . preg_quote('delimiter', '~') . '\s*([^\s]+)$~iS', end($query), $matches) === 1){ //DELIMITER DIRECTIVE DETECTED array_pop($query); //WE DON'T NEED THIS LINE IN SQL QUERY if( $otherDelimiter = ( $matches[1] != $delimiter )){ }else{ //THIS IS THE DEFAULT DELIMITER, DELETE THE LINE BEFORE THE LAST (THAT SHOULD BE THE NOT DEFAULT DELIMITER) AND WE SHOULD CLOSE THE STATEMENT array_pop($query); $query[]=$delimiter; } } if ( !$otherDelimiter &amp;&amp; preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1) { $query = trim(implode('', $query)); if (mysql_query($query) === false){ echo '&lt;h3&gt;ERROR: ' . $query . '&lt;/h3&gt;' . "\n"; }else{ echo '&lt;h3&gt;SUCCESS: ' . $query . '&lt;/h3&gt;' . "\n"; } while (ob_get_level() &gt; 0){ ob_end_flush(); } flush(); } if (is_string($query) === true) { $query = array(); } } return fclose($file); } } return false; } </code></pre> <p>I hope i could help somebody too. Have a nice day!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload