Käynnissä

Generate a .SQL file to create database with settings from an XML file

I have an XML-file specifying database, tables and fields. I need an PHP-script that generates a SQL file that creates this tables and fields.

Input (a real example see attached file):

--- [url removed, login to view] ---

<Project ProjName="dbtest">

<Database DBName="dbtest" >

<Table TblSchema="" TblName="tbltest" TblType="TABLE">

<Field FldName="id" FldTypeName="INT" FldSize="11" FldIsPrimaryKey="1" FldAutoIncrement="1"/>

<Field FldName="name" FldTypeName="VARCHAR" FldSize="20" FldIsPrimaryKey="0" FldAutoIncrement="0"/>

</Table>

</Database>

</Project>

--- END: [url removed, login to view] ---

The output whould be somthing like this:

--- [url removed, login to view] ---

CREATE TABLE `tbltest` (

`id` int(11) NOT NULL,

`field` varchar(10) DEFAULT NULL,

`field2` varchar(10) NOT NULL,

`field3` date NOT NULL,

`field4` smallint(6) NOT NULL,

`field5` decimal(10,0) NOT NULL,

`field6` tinyint(1) NOT NULL,

`field7` longblob NOT NULL,

`field8` datetime NOT NULL,

`field9` date NOT NULL

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `tbltest`

ADD PRIMARY KEY (`id`);

ALTER TABLE `tbltest`

MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--- END: [url removed, login to view] ---

I tried to do it myself but knowledge and time was not enough for me, but here is what I started with (it's not working):

--- [url removed, login to view] ---

echo "Starting...";

$xml = simplexml_load_file("[url removed, login to view]");

$nodes = $xml->xpath('/Project/Database/Table');

foreach ($nodes as $table)

{

if ($table['TblName']=='TABLE')

{

echo "CREATE TABLE `" . $table['TblName'] . "` (";

foreach ($table->children() as $field)

{

echo "`" .$field['FldName']. "` " .$field['FldTypeName'];

if (!($field['FldTypeName']=='DATETIME' || $field['FldTypeName']=='DATE' || $field['FldTypeName']=='TIME' || $field['FldTypeName']=='TIMESTAMP' || $field['FldTypeName']=='LONGTEXT' || $field['FldTypeName']=='TEXT' || $field['FldTypeName']=='TINYTEXT'))

echo "(" .$field['FldSize']. ")";

echo ",";

}

echo ") ENGINE=MyISAM DEFAULT CHARSET=utf8;";

}

}

--- END: [url removed, login to view] ---

I don't have a xml-schema but I have added a project file (xml) with .sql file. THEY ARE NOT TOTALLY MATCHING because the database is old (this is the reason for this project) but should describe fields in xml file with sql...

And the sql-file that belongs to eventplan.xml..

Taidot: PHP

Näytä lisää: access database create xml file, create database php script install sql file, software write mq4, software write chip epson, useful software write book, software write web specs, free software write user guide, software write edid, free software write company profile, software write websites idea, software write book images, database create schema sql mssql, software write books, software write protection, free software write book, create generate pdf file perl, software write book, create paragraph sql database, php sql database create file, sql server create tabel csv file

Tietoa työnantajasta:
( 8 arvostelua ) Bagarmossen, Sweden

Projektin tunnus: #13281579

12 freelanceria on tarjonnut keskimäärin %project_bid_stats_avg_sub_26% %project_currencyDetails_sign_sub_27% tähän työhön

infowider11

Hello, Hope your doing well. I m a Web Designer cum Developer with 7 years' of experience.I just go through your requirement. I m showing interest in this job because i have good knowledge of Mobile Jquery, W Lisää

kr163 SEK 1 päivässä
(47 arvostelua)
6.2
sljukic

Hi, I've got 15+ years of experience in IT development, of which 10+years in web development using PHP/HTML/Javascript/AJAX/mySQL technologies. I worked in a bank for 10 years during which I worked as a programme Lisää

kr1111 SEK 3 päivässä
(28 arvostelua)
5.6
pakulin

Hi, need xml schema used to describe SQL. Do you need any validations? .

kr162 SEK 1 päivässä
(35 arvostelua)
5.4
leliksansl

can make this script ..................... ..................... ..................... ..................... ..................... .....................

kr162 SEK 1 päivässä
(63 arvostelua)
5.2
kr163 SEK 1 päivässä
(31 arvostelua)
4.8
MrSabir

Hey there :-) I can do that for you pretty fast. I will need your database username, database password and database name and I can write you a php script that creates all your tables and fields :-) Send me a mess Lisää

kr192 SEK 0 päivässä
(25 arvostelua)
4.4
kingsnigdho

Hi, I'm a PHP Web developer. After reading your job description, I think the job is best suited to me. Currently I am working on a Classified Ads Site. You can check out its live demo: [login to view URL] Lisää

kr122 SEK 1 päivässä
(35 arvostelua)
4.6
loayvb

Hi, I can help you finish this PHP script. I am web and mobile developer and I am also capable of parsing files based on their grammar. If you have any questions please let me know.

kr70 SEK 2 päivässä
(3 arvostelua)
1.4
sheinwaiyanlin

A proposal has not yet been provided

kr182 SEK 0 päivässä
(2 arvostelua)
1.0
kr163 SEK 1 päivässä
(2 arvostelua)
1.0
franco0808

A proposal has not yet been provided

kr132 SEK 1 päivässä
(2 arvostelua)
0.6
yasmeenkhalaf94

A proposal has not yet been provided

kr102 SEK 2 päivässä
(0 arvostelua)
0.0