/** * Explodes a SQL string into an array of SQL statements. * @example * <code> * echo SqlParser::parseString("-- Table foo * DROP TABLE foo; * CREATE TABLE foo ( * id int(11) NOT NULL AUTO_INCREMENT, * title varchar(255) NOT NULL, * PRIMARY KEY (id), * ) ENGINE=InnoDB;"); * // results in * // array( * // "DROP TABLE foo;", * // "CREATE TABLE foo ( * // id int(11) NOT NULL AUTO_INCREMENT, * // title varchar(255) NOT NULL, * // PRIMARY KEY (id), * // ) ENGINE=InnoDB;" * // ) * </code> * @param string $input The SQL code to parse * * @return array A list of SQL statement strings */ public static function parseString($input) { $parser = new self(); $parser->setSQL($input); $parser->convertLineFeedsToUnixStyle(); $parser->stripSQLCommentLines(); return $parser->explodeIntoStatements(); }