Syntax to export 4 MySQL DB tables to XML? - php

I'm trying to create a PHP file that will export the contents of 4 tables in my MySQL database to an XML file that will be downloaded to the workstation. The tables are orders, orders_products, orders_products_attributes and orders total.
I am able to do the export to xml via phpmyadmin for these tables, but it doesn't show me the syntax it's using to create it.
Any help would be appreciated!

Invoke the following command from a shell_exec() inside PHP. You'd need to add your login details alongside the -p option, of course.
mysqldump -p --xml databasename orders orders_products orders_products_attributes orders > dump.xml
details here.

Related

Exporting data from database to xml

I need to save data from a relational database record set in MySQL (composed of multiple tables and multiple sub-records for each master record) to an xml file. My questions are:
Is there an xml standard format for defining the relation between the database structure and the xml to output?
Are there recommended open-source libraries in PHP that would do the job?
It is possible to export and import XML data using the mysql monitor.
$ mysql -uroot -p --xml -e 'SELECT * FROM tablename' > /tmp/tabllename.xml
The mysql monitor has an --xml option, which enables us to dump data in XML format. The -e option executes a statement and quits the monitor.
For whole database you can use mysqldump tool
mysqldump --xml databasename > databasename.xml
or
mysqldump -X databasename> databasename.xml
Hope it helps!!

Mysql Error #2002 No Connection made.

I know previously several question had been posted on this topic. But mine is a bit difference. I already tried all the previous solution. What happened is whenever I try to select data from a specific table mysql crashes. I do work fine on all other tables but whenever I select data from that specific table it crashes even from command line. Now I am unable to mysqldump the database and also cant drop the table as it contains valuable data. Please suggest some options.
Use mysqlcheck to check specific table in db.
mysqlcheck -c db_name tbl_name -u root -p
provide password and it will tell you whether your table is corrupted or not.
Then you can use following command to repair table
mysqlcheck -r db_name tbl_name -u root -p
mysqlcheck work with MyISAM and archive tables.
After several attempts and various suggestions from you guys I finally find a somewhat solution. It is true that the specific table was corrupted. And all other above mentioned options failed. So, I executed a query with limiting my results to 0, 100 and it works fine. Then I dump that data by using that query with mysqldump. I keep on going and changed the limit from 100, 200 and so on. Whenever I get error I simply skipped few rows. At last I had recovered almot 95% of my data which is not bad. Thanks guys for all your support.

How can I convert MySQL database to SQLite in PHP?

I need PHP code to convert the database. I tried How to convert mysql to SQLite using PHP but it dint have answer
I finally found its solution.
Save sh file available at
https://gist.github.com/943776
and execute
"./mysql2sqlite.sh DBNAME --databases DBNAME -u DB_USERNAME -pDB_PASSWORD | sqlite3 database.sqlite"(without qoutes and with "`")
in php file.
Save both files in one folder
Go to phpmyadmin
click export database
download as sql file.
Download it....
go to your sql lite management software
import the .sql file
done...

How to Create a Schema in MySQL?

How to create a schema with existing tables. I have 100 tables then now I want to create a schema for this table can you tell the procedure how or any tools.
I am trying the TOAD but it shows the result in HTML format. I want the result in SQL.
How create a schema using PHP.
A single show create table <tablename> statement in mysql command line tool will suffice, if you want schema only and no data. The result will be a full create table ddl
Take Dump of all table so you get schema...refer this Dump
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
mysqldump --user MYSQL_USER --password=MYSQL_PASSWORD --add-locks --flush-privileges \
--add-drop-table --complete-insert --extended-insert --single-transaction \
--database DB_TO_BACKUP > FILENAME_FOR_SQL_STATEMENTS
this will give a file full of SQL create and insert statements that can be used to recreate the DB. The back slashes "\" are continue to next line... you may want to ignore it and write the whole command in one line
Now, I am not sure if you wanted to the whole Db with data or just tables... you may want to use --no-data to get rid of insert SQL statements and just create and delete (and lock) statements, e.g.
mysqldump --user MYSQL_USER --password=MYSQL_PASSWORD --add-locks --flush-privileges \
--add-drop-table --no-data --single-transaction \
--database DB_TO_BACKUP > FILENAME_FOR_SQL_STATEMENTS
http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html#option_mysqldump_no-data
That is:
mysqldump --no-data -u <username> -p --database <dbname> <further options> > <dbname>.sql
from the command line, on the server (perhaps via ssh).
...can you tell the procedure how or any tools
You can use 'Generate Schema Script' or 'Backup' GUI tool in dbForge Studio for MySQL.
Limited Backup is available in free express version, the size of backup files is limited to 1MB, it is enough for 100 table schemas.
You can use mysql workbench, connect with existing database there and you can import and export the schema in sql formats

How can i use php to export a mysql table

I am trying to export just the rows of a mysql table without the table information to an xml file. I read that the mysqldump command will get the job done but I cant manage to get the correct syntax. Can someone post an example code for mysqldump command? Thank you.
$command="mysqldump --xml ";
Try the script on this page: http://www.chriswashington.net/tutorials/export-mysql-database-table-data-to-xml-file
By any chance you are not trying to run that command inside mysql_query are you ? It wont work that way. mysqldump is a command line utility.
To run it from php you would need to use the system() function, documentation - http://php.net/manual/en/function.system.php
If you are on a shared host with PHP in safe mode, or the system function is explicitly disabled in php.ini, then you will not be able to do this.
In that case you would need to read the data from your table using a SELECT query and iterating on all rows and potting it into an XML file, using XMLWriter or DOMDocument

Categories