Is it possible to select all the tables from a database (not knowing their names) and displaying them?
My friend has a mysql server but he doesn't have phpMyAdmin installed and he's begging me to transfer all his php-fusion accounts to his new WordPress blog. He doesn't understand a thing with mysql...
Anyone got an idea?
Use the SHOW and DESCRIBE statements. That's all phpMyAdmin is doing in the code. Your SQL user should have privileges.
List all tables:
SHOW tables;
List table definition:
DESCRIBE table_name;
Check out MySQL for more details.
Related
I have written a query in PhpMyadmin to fetch data from two databases running in the same server, and is working fine. But I am not sure how to use this query in PHP code. This query contains RIGHT JOIN and other sub-queries. Even if I open two DB connections, how will I execute this query and which Connection should I use?
Eg.
Database A: Table: accountmaster (contains the profile details of the users, with IDs for City, State etc)
Database B: All masters (City, State etc)
Query: fetching all profile entries by joining these two databases.
If you share your query, I think we could elaborate on more precise answers.
Probably your question is already answered here.
Firstly, you should use one connection from any database. I would prefer to connect to database A, once it contains the references to database B and makes sense for me to request join data from B.
As discussed in the link, it is necessary that the user has the privileges to execute the query.
Finally, it is just to write your query as discussed here - as a string - and pass it as a parameter to mysqli query.
I'm working on joomla plugin that could help me with backups of my site.
I have problem with copying database of one site to another. Both databases have different users. I tried to use query like that:
INSERT INTO new_table SELECT * FROM another_database.old_table
Unfortunately I got an error:
SELECT command denied to user 'user_old'#'ip' for table 'old_table'
I understand an error, but I cant create another user that could have priviliges to both databases.
Can I somehow work this out in php? I create connection to both databases, but is there a way of doing this other than
SELECT * FROM old_table
then inserting all data fetched to new_table?
I would like to not use mysqldump because I want to have control which tables I will copy.
You can use mysqldump to get all the tables, load that sql file into the new database and then run:
DROP TABLE <table_name>;
on all the tables you do not want in the new database.
What does "Add DROP SYNTAX" in the XCloner plugin mean?
I checked the manual and it says something I don't understand.
Add MySQL Drop:
Tick this checkbox if you want XCloner to add the DROP TABLE IF
EXISTS statement to your generated SQL. This option is only for
advanced users.
How important is this to check? and will I lose anything if I ignore it? Please explain in both short and long answers.
Thank you.
If you enable this option, the resulting exported SQL will contain DROP TABLE IF EXIST statements. This means that when you try and import said SQL into another database, it will DROP any existing tables that have the same names as the tables contained in the SQL. If I export the tables users, items and news from Database A and I attempt to import them into Database B, any tables with those names will be dropped before those three tables are imported. So, if I already have a table called users in Database B, it will be dropped before the "new" users table is imported. Could be disastrous if you have another app connected to Database B that also uses its own table called users.
i'm new in asking questions here in the site, here is the situation:
Im using a Xampp Control Panel,
I have two systems, the old one and the new one (the new one is just the upgraded version of the old one).
I have 2 databases, let's name it db1 and db2, (db1 is the dbase used for the old one, and db2 is the dbase used for the new one.)
both databases have the same tables and contents except for one table, in db1.tb_final_dtr the structure has only 10 columns while db2.tb_final_dtr has 11 columns though the 10 columns in each table is the same with each other, and also both tables have the same records.
-I tried to queried both database with simple query lets say "SELECT * FROM tb_final_dtr WHERE hr_id = 'ASM12-0101'", the problem is, db1 shown 10 records right away, while db2 shown empty result. They both have the same table structure and records, they just differ in database name and the number of columns in one table.
WHAT SEEMS TO BE THE PROBLEM? hope you can reply at my question right away. Thanks a lot.
Your DB_2 is not working on NEW system..
Go to PHPmyadmin (on your NEW system) and add new user with username & password written from your conf file (and server name as localhost) of your website :P
So
go to PMA
add new user
enter data (server, username, password)
reload mysql
Of course, DB name in config file may also be wrong if tables are duplicated who knows what so check that too.
Good luck!
I have some data in another database which is separate from the wordpress database on my mysql installation.
I've heard that it can be a little tricky to get data from a different database as wordpress assumes you'll just want wordpress data.
Since it's just one table, can I get by with just creating a cross database view in the wordpress database? Are there performance considerations to think about?
I would just give permission through mysql to allow your wordpress database user to access the other table. This will work fine.
Two databases:
DB1
Table1
Table2
DB2
Table3
Table4
Then all you do is something like this:
select * from DB1.table1, DB2,table3 where DB1.field1 = DB2.field1
Hope that makes sense :)