MySQL架构XML导出
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL架构XML导出相关的知识,希望对你有一定的参考价值。
Export entire database schema to local xml file.
private function execute( $sql ) { } /** * I save the entire database schema to a local xml file. * * @param [string] $database the name of your database * @return [result] true or false */ public function saveSchemaXML( $database ) { $dom = new DOMDocument ( '1.0' ); /************************************ * Builds the root ************************************/ //create a element $schema = $dom->createElement ( 'schema' ); //set the element on itself $schema = $dom->appendChild ( $schema ); //set a attribute for the schema node $schema->setAttribute ( 'name', $database ); /*********************************** * Builds the table inside the root **********************************/ $tableQuery = $this->execute ( "SHOW TABLES FROM $database" ); { //create a element $table = $dom->createElement ( 'table' ); //set the element on itself $table = $dom->appendChild ( $table ); //set a attribute $table->setAttribute ( 'name', $tableRow [ 0 ] ); $fieldQuery = $this->execute ( "DESCRIBE $database.$tableRow[0]" ); { /*********************************** * Builds the attributes inside the table **********************************/ //create a element $field = $dom->createElement ( 'field' ); //set the element on itself $field = $dom->appendChild ( $field ); //set the name attribute $field->setAttribute ( 'name', $fieldRow [ 'Field' ] ); //set the type attribute $field->setAttribute ( 'type', $this->replaceNumbers ( $fieldRow [ 'Type' ] ) ); //set the null attribute if ( $fieldRow [ 'Default' ] != '' ) { //set the default } if ( $fieldRow [ 'Key' ] != '' ) { //set the key } if ( $fieldRow [ 'Extra' ] != '' ) { //set the value/length attribute } //put the field inside of the table $table->appendChild ( $field ); } //put the table inside of the schema $schema->appendChild ( $table ); } $dom->formatOutput = true; $dom->saveXML (); //save the file $xml = $dom->save ( $filename ); //change the permissions return $xml; }
以上是关于MySQL架构XML导出的主要内容,如果未能解决你的问题,请参考以下文章