from mysql to php

Hi

is there any already existing framework that starting from a mysql table
structure generates the php code to generate that table structure?

Of course it can be programmed with
http://it2.php.net/manual/en/function.mysql-list-fields.php but I was
wondering if there's some framework that already does this...

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 12:03 ] [ ID #1596024 ]

Re: from mysql to php

Lorenzo Bettini schreef:
> Hi
>
> is there any already existing framework that starting from a mysql table
> structure generates the php code to generate that table structure?
>
> Of course it can be programmed with
> http://it2.php.net/manual/en/function.mysql-list-fields.php but I was
> wondering if there's some framework that already does this...
>
> thanks in advance
> Lorenzo
>
Yes, it's called phpMyAdmin

--
Arjen
http://www.hondenpage.com - Mijn site over honden
Dave Williams [ Mo, 15 Januar 2007 13:57 ] [ ID #1596026 ]

Re: from mysql to php

Arjen wrote:
> Lorenzo Bettini schreef:
>> Hi
>>
>> is there any already existing framework that starting from a mysql table
>> structure generates the php code to generate that table structure?
>>
>> Of course it can be programmed with
>> http://it2.php.net/manual/en/function.mysql-list-fields.php but I was
>> wondering if there's some framework that already does this...
>>
>> thanks in advance
>> Lorenzo
>>
> Yes, it's called phpMyAdmin
>

Hi

I'm already using phpmyadmin but didn't find this functionality and I
can't still find it... could you please be more specific?

thanks
Lore

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 14:15 ] [ ID #1596027 ]

Re: from mysql to php

Lorenzo Bettini wrote:
> Arjen wrote:
>> Lorenzo Bettini schreef:

>>> is there any already existing framework that starting from a mysql table
>>> structure generates the php code to generate that table structure?
>>> Of course it can be programmed with
>> Yes, it's called phpMyAdmin
> I'm already using phpmyadmin but didn't find this functionality and I
> can't still find it... could you please be more specific?

I guess you have to specify more clearly what you want, as phpMyAdmin does
show you column data, just select a database and then click on one of the
tables and you get the column names and types and so on.

If you mean a php script that takes a tables as argument and spits out
php-code how to get out the data in a nice table format, which you then can
cut'n'paste to your own script, no there isn't a such script.
It's not that difficult to make a function that works for all tables.

So please, specify more clearly what do you want to do.

--

//Aho
Shion [ Mo, 15 Januar 2007 15:01 ] [ ID #1596028 ]

Re: from mysql to php

J.O. Aho wrote:
> Lorenzo Bettini wrote:
>> Arjen wrote:
>>> Lorenzo Bettini schreef:
>
>>>> is there any already existing framework that starting from a mysql
>>>> table
>>>> structure generates the php code to generate that table structure?
>>>> Of course it can be programmed with
>>> Yes, it's called phpMyAdmin
>> I'm already using phpmyadmin but didn't find this functionality and I
>> can't still find it... could you please be more specific?
>
> I guess you have to specify more clearly what you want, as phpMyAdmin
> does show you column data, just select a database and then click on one
> of the tables and you get the column names and types and so on.
>
> If you mean a php script that takes a tables as argument and spits out
> php-code how to get out the data in a nice table format, which you then
> can cut'n'paste to your own script, no there isn't a such script.
> It's not that difficult to make a function that works for all tables.
>
> So please, specify more clearly what do you want to do.
>

OK, I need a php framework that reads the structure of a mysql table and
generates php code that can recreate that table in another mysql database.

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 15:34 ] [ ID #1596029 ]

Re: from mysql to php

Lorenzo Bettini wrote:

> OK, I need a php framework that reads the structure of a mysql table and
> generates php code that can recreate that table in another mysql database.

What about using mysqldump?

--

//Aho
Shion [ Mo, 15 Januar 2007 15:53 ] [ ID #1596031 ]

Re: from mysql to php

J.O. Aho wrote:
> Lorenzo Bettini wrote:
>
>> OK, I need a php framework that reads the structure of a mysql table
>> and generates php code that can recreate that table in another mysql
>> database.
>
> What about using mysqldump?
>

I know that too, but I'd like then to be able to recreate the table from
php; do you actually suggest to load from php that file and using a
mysql_xxx command to recreate the table?

I'd like to have a finer grain control: e.g., being able to have all the
structure fields, but create only on field...

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 15:59 ] [ ID #1596032 ]

Re: from mysql to php

Lorenzo Bettini wrote:
> is there any already existing framework that starting from a mysql table
> structure generates the php code to generate that table structure?
>

<semantic mode>
It wouldn't actually *be* PHP code, but MySQL code that generates the
structure. PHP would just be calling its various MySQL functions to
accomplish the task. Though true, it would be PHP code that would have
to extract the data returned by the MySQL calls.
</semantic mode>

That being said, for freeware you could try
http://sourceforge.net/projects/phpmydoc

But it's kinda old, not sure if it works. I fiddled with it and
couldn't get past the welcome screen, it had a funny if based on a var
that only exists in the if, and the form generated in the welcome screen
had no target for the POST. Didn't give it too hard a look, but since
the code is from '02, some of it may be deprecated to the version of PHP
I'm on (5.2.0)
Carl Pearson [ Mo, 15 Januar 2007 16:19 ] [ ID #1596033 ]

Re: from mysql to php

Carl Pearson wrote:
> Lorenzo Bettini wrote:
>> is there any already existing framework that starting from a mysql table
>> structure generates the php code to generate that table structure?
>>
>
> <semantic mode>
> It wouldn't actually *be* PHP code, but MySQL code that generates the
> structure. PHP would just be calling its various MySQL functions to
> accomplish the task. Though true, it would be PHP code that would have
> to extract the data returned by the MySQL calls.
> </semantic mode>
>
> That being said, for freeware you could try
> http://sourceforge.net/projects/phpmydoc
>
> But it's kinda old, not sure if it works. I fiddled with it and
> couldn't get past the welcome screen, it had a funny if based on a var
> that only exists in the if, and the form generated in the welcome screen
> had no target for the POST. Didn't give it too hard a look, but since
> the code is from '02, some of it may be deprecated to the version of PHP
> I'm on (5.2.0)

yes, your semantic explanation is correct: I need to generate php code
that calls specific mysql functions to recreate the structure of a mysql
table.

phpmydoc seems to only generate documentation, as far as I understand...

the generated php code I have in mind would be used, e.g., in an
installation procedure to generate (or, more interestingly, update) the
tables of the database.

Lore

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 16:27 ] [ ID #1596034 ]

Re: from mysql to php

Lorenzo Bettini wrote:
> J.O. Aho wrote:
>> Lorenzo Bettini wrote:
>>
>>> OK, I need a php framework that reads the structure of a mysql table
>>> and generates php code that can recreate that table in another mysql
>>> database.
>>
>> What about using mysqldump?
>>
>
> I know that too, but I'd like then to be able to recreate the table from
> php; do you actually suggest to load from php that file and using a
> mysql_xxx command to recreate the table?

Yes, php calls mysqldump and creates you a sql file, which you can then upload
to your other database and use mysqldump to inject it.


> I'd like to have a finer grain control: e.g., being able to have all the
> structure fields, but create only on field...

You can process the mysqldump output and remove things you don't want to transfer.


--

//Aho
Shion [ Mo, 15 Januar 2007 16:32 ] [ ID #1596035 ]

Re: from mysql to php

J.O. Aho wrote:
> Lorenzo Bettini wrote:
>> J.O. Aho wrote:
>>> Lorenzo Bettini wrote:
>>>
>>>> OK, I need a php framework that reads the structure of a mysql table
>>>> and generates php code that can recreate that table in another mysql
>>>> database.
>>>
>>> What about using mysqldump?
>>>
>>
>> I know that too, but I'd like then to be able to recreate the table
>> from php; do you actually suggest to load from php that file and using
>> a mysql_xxx command to recreate the table?
>
> Yes, php calls mysqldump and creates you a sql file, which you can then
> upload to your other database and use mysqldump to inject it.
>
>
>> I'd like to have a finer grain control: e.g., being able to have all
>> the structure fields, but create only on field...
>
> You can process the mysqldump output and remove things you don't want to
> transfer.

yes, and I was wondering whether there's something that already does
this, without having to program it.

Consider the scenario where you have a database with tables that need to
be updated to a new version (some structures have changed).

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 15 Januar 2007 17:00 ] [ ID #1596037 ]

Re: from mysql to php

Lorenzo Bettini wrote:
> Carl Pearson wrote:
> the generated php code I have in mind would be used, e.g., in an
> installation procedure to generate (or, more interestingly, update) the
> tables of the database.

Ultimately it's just a bunch of calls to mysql_query().

You could use phpMyAdmin to dump your existing structure into a file,
incorporating it into your install script, using your text editor's
search & replace capabilities to wrangle the dump into shape. A chore,
but still you'd only have to do it once, and having a dump would save
you from having to type all those table defs by hand.

For updates, are you talking about the data, or the structure?

If data, just create the appropriate queries and have your script turn
the results into insert statements (don't run them on the same database,
just use PHP to add the "INSERT INTO" & other code before it echo's or
prints anything out...), saving that as a file. Am presuming here you'd
run the queries on one machine and the resulting file on another.

For structure, you really shouldn't be changing that too much once the
database is up & running, so that would just be another bunch of
statements that you'd design ahead of time, stuffing them all into a
script similar to the structure generation method above.

Good luck!
--
Carl
Carl Pearson [ Mi, 17 Januar 2007 00:13 ] [ ID #1597356 ]

Re: from mysql to php

Carl Pearson wrote:
> Lorenzo Bettini wrote:
>> Carl Pearson wrote:
>> the generated php code I have in mind would be used, e.g., in an
>> installation procedure to generate (or, more interestingly, update)
>> the tables of the database.
>
> Ultimately it's just a bunch of calls to mysql_query().
>
> You could use phpMyAdmin to dump your existing structure into a file,
> incorporating it into your install script, using your text editor's
> search & replace capabilities to wrangle the dump into shape. A chore,
> but still you'd only have to do it once, and having a dump would save
> you from having to type all those table defs by hand.
>
> For updates, are you talking about the data, or the structure?
>
> If data, just create the appropriate queries and have your script turn
> the results into insert statements (don't run them on the same database,
> just use PHP to add the "INSERT INTO" & other code before it echo's or
> prints anything out...), saving that as a file. Am presuming here you'd
> run the queries on one machine and the resulting file on another.
>
> For structure, you really shouldn't be changing that too much once the
> database is up & running, so that would just be another bunch of
> statements that you'd design ahead of time, stuffing them all into a
> script similar to the structure generation method above.
>

I'm actually talking about updating the structure.

What I do now is change the structure from phpmyadmin, copy the sql code
that phpmyadmin writes into a an sql file and tell the users to update
the database with that file (using a mysql command line).

I was looking for a more friendly way (say a page update.php) that
automatically checks the difference between the current version of the
database structure and the new one (when a new release of the software
is shipped).

Possibly, I'd like to avoid writing these things manually, and have
these procedures generated automatically.

This way the update procedure comes with its own structure of the
database, checks it agains the current version (i.e., performs a kind of
diff) and then brings the old structure to the new one...

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Fr, 19 Januar 2007 19:09 ] [ ID #1601690 ]

Re: from mysql to php

Lorenzo Bettini wrote:

> What I do now is change the structure from phpmyadmin, copy the sql code
> that phpmyadmin writes into a an sql file and tell the users to update
> the database with that file (using a mysql command line).

> I was looking for a more friendly way (say a page update.php) that
> automatically checks the difference between the current version of the
> database structure and the new one (when a new release of the software
> is shipped).

This is a page you have to write yourself, you can check if the tables has
those changes you are supposed to have if the tables are up to date, if there
is a fail, then you know you need to make the update, to make the update.php
to handle different versions of your db design you have to check things one at
the time.


> Possibly, I'd like to avoid writing these things manually, and have
> these procedures generated automatically.

As there are so many small things you can change, it's difficult to make a
good general script (don't say it's impossible or anything like that), it's a
lot easier to make your own update scripts. Myself I have always done a php
file that can be run easily without any sql skills.

You can even take this a level higher and include checks in the regular php
code that checks if the database is up to date if a sql query fails, if it
notice that the database isn't of the right format, it updates the database
and then redo the sql query, this way the user don't have to run any
update.php or run a sql file.

--

//Aho
Shion [ Fr, 19 Januar 2007 19:34 ] [ ID #1601691 ]

Re: from mysql to php

J.O. Aho wrote:
> Lorenzo Bettini wrote:
>
>> What I do now is change the structure from phpmyadmin, copy the sql code
>> that phpmyadmin writes into a an sql file and tell the users to update
>> the database with that file (using a mysql command line).
>
>> I was looking for a more friendly way (say a page update.php) that
>> automatically checks the difference between the current version of the
>> database structure and the new one (when a new release of the software
>> is shipped).
>
> This is a page you have to write yourself, you can check if the tables
> has those changes you are supposed to have if the tables are up to date,
> if there is a fail, then you know you need to make the update, to make
> the update.php to handle different versions of your db design you have
> to check things one at the time.
>
>
>> Possibly, I'd like to avoid writing these things manually, and have
>> these procedures generated automatically.
>
> As there are so many small things you can change, it's difficult to make
> a good general script (don't say it's impossible or anything like that),
> it's a lot easier to make your own update scripts. Myself I have always
> done a php file that can be run easily without any sql skills.

that was exactly my point: since it can be done automatically (but not
easily) I was wondering whether some one already did that

>
> You can even take this a level higher and include checks in the regular
> php code that checks if the database is up to date if a sql query fails,
> if it notice that the database isn't of the right format, it updates the
> database and then redo the sql query, this way the user don't have to
> run any update.php or run a sql file.
>

yes, but this would perform the check for every sql query... it might
have too much overhead...


--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Mo, 22 Januar 2007 14:23 ] [ ID #1604192 ]

Re: from mysql to php

Lorenzo Bettini wrote:

>> You can even take this a level higher and include checks in the
>> regular php code that checks if the database is up to date if a sql
>> query fails, if it notice that the database isn't of the right format,
>> it updates the database and then redo the sql query, this way the user
>> don't have to run any update.php or run a sql file.

> yes, but this would perform the check for every sql query... it might
> have too much overhead...

You can do as many of the portal systems does, provide a script that updates
from previous version to current version, if someone has skipped an update,
then it's kind of their problem.

--

//Aho
Shion [ Mo, 22 Januar 2007 15:21 ] [ ID #1604193 ]

Re: from mysql to php

J.O. Aho wrote:
> Lorenzo Bettini wrote:
>
>>> You can even take this a level higher and include checks in the
>>> regular php code that checks if the database is up to date if a sql
>>> query fails, if it notice that the database isn't of the right
>>> format, it updates the database and then redo the sql query, this way
>>> the user don't have to run any update.php or run a sql file.
>
>> yes, but this would perform the check for every sql query... it might
>> have too much overhead...
>
> You can do as many of the portal systems does, provide a script that
> updates from previous version to current version, if someone has skipped
> an update, then it's kind of their problem.
>

I'm already doing this :-)

--
Lorenzo Bettini, PhD in Computer Science, DSI, Univ. di Firenze
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Lorenzo Bettini [ Di, 23 Januar 2007 08:51 ] [ ID #1605330 ]
PHP » alt.php » from mysql to php

Vorheriges Thema: PHP Version 5.1.6 versus PHP Version 4.3.10
Nächstes Thema: 2 submision buttons & IE problem