Page 1 of 1
Is this possible?
Posted: Fri Jan 27, 2006 10:37 am
by jclarkkent2003
Is it possible to echo ALL the currentely set variables in a script? I'm trying to modifiy a wordpress 2.0 plugin for my own needs, but it's got issues.
It's supposed to recreate all the tables and insert data (for a multi blog setup) and it only sets up ONE "set" of all the tables each time, and then each additional time it loops, it doesn't create the tables. I need to know WHY as I can't figure it out.
I tried putting
ob_start()
ob_flush()
ob_end_clean();
INSIDE the for loop but BEFORE and AFTER the contents of that for loop, so I Was trying for it to do whatever it needed to do then do it again and again... but its' not working, so I need to know what varible is causing additional tables from being created......
Thanks.
Posted: Fri Jan 27, 2006 10:47 am
by feyd
the globals superglobal array will have any variables defined in the global space.
get_defined_constants()
get_defined_functions()
get_declared_classes()
may also be of interest.
Posted: Fri Jan 27, 2006 11:00 am
by jclarkkent2003
k yea I knew about that, but all the variables are not defined in the $GLOBALS array is the thing, there is no other way to display the entire set variables in a script?
Oh, something else SUPER important, Is it possible to COPY a mysql table inside a database ? I know about the RENAME database1 TO database2 but that gets rid of one, it just renames it. I need something to duplicate a entire TABLE inside one database from PHP code (not from root or shell access).
Is that possible, or is there part of a script somewhere here on this forum that can recuse the entire table, grab it's structure as well and create it again?
Thanks for the super fast response

Posted: Fri Jan 27, 2006 11:03 am
by feyd
If the variables aren't available in the global space, you'll have to figure out how to get to them, but it should be traversable through the global.
As for your secondary question: Look into the
INSERT .. SELECT syntax
Posted: Fri Jan 27, 2006 1:25 pm
by jclarkkent2003
ok great, that worked really well, but i'm wondering if it can be done a little more automatically....
Here is what worked:
Code: Select all
INSERT `z_blog_wp_100_options` (option_id,blog_id,option_name,option_can_override,option_type,option_value,option_width,option_height,option_description,option_admin_level,autoload) SELECT * FROM `z_blog_wp_options`;
and here is what DID NOT work but I'm wondering if it can be done like this, did I get syntax a little messed up?
Code: Select all
INSERT `z_blog_wp_100_options` * SELECT * FROM `z_blog_wp_options`;
The idea here is not having to list all the rows in the table, but instead copy each and every table ALL rows. Is there a way to insert ALL rows
....
Son of a gun, lol, figured it out while typing.....
Here is how to copy a ENTIRE table within a database for anyone who's looking:
Code: Select all
INSERT `newtable` SELECT * FROM `oldtable`;
I still have to find out how to get the database structure of oldtable and create newtable with the same database... Anyone know how to do that easily (basically how do I grab the structure of database1 so i can create database2 with same structure FROM PHP)? ( I don't want to waste time looking up that, right now, inside phpadmin I just went to export and exported the table, copied the structure and renamed, which will work ATM but isn't my final goal....
Posted: Fri Jan 27, 2006 3:04 pm
by raghavan20
This is the command to create a table like another existing table
Code: Select all
create table new_table like old_table
I have not seen a command to create a database like another...but this is how you should usually duplicate a database;
Code: Select all
use show databases;
and for every database returned use show tables;
and for every table returned, run show create table table_name
Posted: Fri Jan 27, 2006 3:10 pm
by jclarkkent2003
nice, thank you, I will look into that for very near future upgrading of the script i'm writing, I like to make it universal, so it can go anywhere and do anything, not restricted lol....
that's me ^_^
Posted: Fri Jan 27, 2006 3:14 pm
by raghavan20
I have the script with me...I will post it when I get back home...
Posted: Fri Jan 27, 2006 10:06 pm
by jclarkkent2003
cool, thanks

that will save me some precious time and hopefully I can resolve my apache crashing issues....