Forum Moderators: coopster

Message Too Old, No Replies

Create new tables in a database

         

jncr

2:52 am on Nov 27, 2007 (gmt 0)

10+ Year Member



Hi guys,

I need to take the contents of a sql dump (example.sql) and change all occurrences of "master" to "testname" and the run this dump against a database.

I am completely at a loss of how to do this...

Any help is appreciated!

~Jncr

phparion

5:09 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your need to explain it further. Do you want to RENAME your table "master" to "testname" in the .sql file so that when you run it it creates testname table with the same contents etc? if yes, then open .sql file with vi editor (linux) or notepad (windows) and search for ( CREATE TABLE master ), you will find this line in the start of file, and rename master to testname. Then run the file and your new table will be named as testname.

phranque

5:25 am on Nov 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



to do exactly and specifically what you described on *nix systems, type the following :
vi example.sql
:1,$ s/master/testname/g
:wq

jncr

1:59 pm on Nov 27, 2007 (gmt 0)

10+ Year Member



that is what i need to do, but i need to do it at run-time with php, and then execute the new sql code (by the way, there is more than one table in the sql file (about 62))

could you also give details of how to execute a file with this many queties?

thank you

~Jncr

phparion

6:50 am on Nov 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you need to edit the .sql file to rename tables.

If you want to create all the tables in new database then simply dump this .sql file into new database. However, if you want to create only one, renamed, table then open .sql file and start copying the code from CREATE TABLE TESTTABLE and end on last INSERT INTO statement, before the next CEATE TABLE nexttablename.

Paste this in a new .sql file and then run this new file only.

It is very simple, mostly editing a text file. I am not sure why are you stuck with it.

3321thec

2:36 pm on Nov 28, 2007 (gmt 0)

10+ Year Member



I have been working with Jncr on this issue, and we run into a problem while saving the new .sql file, some sort of permission denied by the host.

We are now wondering if it is possible to read the procedures from the .sql file, change the tables names, and then run that editied command directly from a variable.

So i guess what I am getting at is, can I run that contents of a .sql file against a database directly from a variable, and if so, with what function?

Thanks

~3321thec