www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: How to export MYSQL to XML with mysqldump --xml

  1. #1
    Join Date
    Apr 2003
    Posts
    234

    Exclamation How to export MYSQL to XML with mysqldump --xml

    Hi,

    1) I want to export a MYSQL table to XML. How I can achieve this?

    2) I read that this can be achieve with mysqldump --xml but how I should use it with PHP ?

    The goal of this is get the data throught http://www.serence.com KLIPFolio

    Thank you on advance.
    _Lobo_
    Last edited by _LOBO_; 06-22-2005 at 10:42 AM.

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    mysqldump is pretty much the only thing that will work, if each your tables has like 1000's of rows, scripts like phpmyadmin will not be capable of exporting large amounts of data

  3. #3
    Join Date
    Apr 2003
    Posts
    234

    Talking

    Thank your for stop here

    So the only hy to export all is mysqldump but how I should use it ? Can you make a samll sample for me creating a XML file with php ? or can you point me to a tutorial ?

    Thank you on advance.
    _Lobo_

    Quote Originally Posted by ShrineDesigns
    mysqldump is pretty much the only thing that will work, if each your tables has like 1000's of rows, scripts like phpmyadmin will not be capable of exporting large amounts of data

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    i don't know the exacts about running mysql-dump from the command-line, this should offer some assistance
    http://dev.mysql.com/doc/mysql/en/index.html

  5. #5
    Join Date
    Apr 2003
    Posts
    234
    ok this si wath I have:

    But im getting this error!

    Notice: Backup failed: 1 in e:\wamp\www\FA06\admin4\xml\xml.php on line 38

    line 38
    PHP Code:
    trigger_error ('Backup failed: '.$error); 
    all my code:
    PHP Code:
    <?php
    $dbUser 
    'root';               // db User 
    $dbPass 'root';               // db User Password 
    $dbName 'newland_tours';            // db name 
    $dest   '/'// Path to directory                

     
    class MySQLDump {
         
    /**
        * The backup command to execute
        * @private
        * @var string
        */
         
    var $cmd;
     
         
    /**
        * MySQLDump constructor
       * @param string dbUser (MySQL User Name)
        * @param string dbPass (MySQL User Password)
        * @param string dbName (Database to select)
        * @param string dest (Full destination directory path for backup file)
        * @access public
        */
         
    function MySQLDump ($dbUser,$dbPass,$dbName,$dest) {
                 
    $fname $dbName.'.xml'
                 
    $this->cmd='mysqldump -X -u'.$dbUser.' -p'.$dbPass.' '.$dbName.
                     
    ' >'.$dest.'/'.$fname;
             }
         
     
         
    /**
        * Runs the constructed command
        * @access public
        * @return void
        */
         
    function backup () {
             
    system ($this->cmd$error);
             if(
    $error)
                 
    trigger_error ('Backup failed: '.$error);
         }
    }

    // Instantiate MySQLDump 
    $mysqlDump = new MySQLDump($dbUser$dbPass$dbName$dest); 

    // Perform the backup 
    $mysqlDump->backup(); 

     
    ?>
    MySQLDump
    • There are three general ways to invoke mysqldump:
      shell> mysqldump [options] db_name [tables]
      shell> mysqldump [options] --databases DB1 [DB2 DB3...]
      shell> mysqldump [options] --all-databases
    • --xml, -X
      Write dump output as well-formed XML.
    • --password[=password], -p[password]
      The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, you are prompted for one.
    • --user=user_name, -u user_name
      The MySQL username to use when connecting to the server.
    Last edited by _LOBO_; 06-23-2005 at 05:56 AM.

  6. #6
    Join Date
    May 2005
    Location
    Boston, MA
    Posts
    199
    Have you tried any debugging?

    Echo out $this->cmd before you use the system call to it. Stuff like that, make sure everything is right.

  7. #7
    Join Date
    Apr 2003
    Posts
    234
    Quote Originally Posted by chrys
    Have you tried any debugging?

    Echo out $this->cmd before you use the system call to it. Stuff like that, make sure everything is right.
    Hi Chris,

    Can you show me how (Im very new with PHP).

  8. #8
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    hmm... you should use empty() to check if there is an error actually occured
    PHP Code:
        function backup()
        {
            
    system ($this->cmd$error);

            if(!empty(
    $error))
            {
                
    trigger_error ('Backup failed: '.$error);
            }
        } 

  9. #9
    Join Date
    Apr 2003
    Posts
    234
    Ok now Im getting this:

    Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in e:\wamp\www\FA06\admin4\xml\xml.php on line 46

    line 46: $mysqlDump = new MySQLDump($dbUser, $dbPass, $dbName, $dest);

  10. #10
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    i tested this and it works
    PHP Code:
    <?php
    class mysql_dump
    {
        var 
    $cmd '';

        function 
    mysql_dump($user$pass$name$path)
        {
            
    $this->cmd "mysqldump -q -X -u {$user} -p{$pass} {$name} -r {$path}{$name}.xml";
        }
        function 
    backup()
        {
            
    passthru($this->cmd$retval);

            if(!empty(
    $retval))
            {
                
    print_r($retval);
            }
        }
    }
    // initilize mysqldump
    $dump = new mysql_dump('root''''test''./');
    // backup database
    $dump->backup();
    ?>

  11. #11
    Join Date
    Apr 2003
    Posts
    234
    Ok I test the file several time and don't work for me I send the file to a friend and he told me that the file was created but with nothing inside. Someone can confirm this please?
    (Something that I found but dont have a clue how to use it someone can show me? http://www.adsworth.info/mysql2xml)
    what is this? XMLDefinition( "localhost", "test", "root", "root", "mos_categories", "rootnodename", "rownodename","iso-8859-1")
    Last edited by _LOBO_; 06-27-2005 at 11:29 AM.

  12. #12
    Join Date
    Apr 2003
    Posts
    234
    Ok someone tell me that the sript work, I don't know what im doin wrong:

    $dump = new mysql_dump('root', 'root', 'mysql', './');

    http://img235.echo.cx/img235/3734/db6sl.gif

    http://img235.echo.cx/img235/3734/db6sl.gif


    now you do it:
    mysql_dump
    Quote Originally Posted by ShrineDesigns
    hmm...
    i have never been able to use it through php, only via the shell
    Last edited by _LOBO_; 06-28-2005 at 03:43 AM.

  13. #13
    Join Date
    Apr 2003
    Posts
    234
    ? anybody

  14. #14
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    mysql is the database for the mysql engine

  15. #15
    Join Date
    Apr 2003
    Posts
    234
    Hi ShrineDesigns,

    Thank you for stop here buddy, yes that is the DB from MYSQL but I try with other DB and nothing happen.

    Im working on Windows Xp SP2 (WAMP server)
    Apache version : Apache/1.3.33 (Win32)
    PHP version : 5.0.4
    MySQL version : 4.1.10a-nt - extension : mysqli

    Any ideas what is wrong ?

    Thank you on advance!

    PHP Code:

    <?php 
    class mysql_dump 

        var 
    $cmd ''

        function 
    mysql_dump($user$pass$name$path
        { 
            
    $this->cmd "mysqldump -q -X -u {$user} -p{$pass} {$name} -r {$path}{$name}.xml"
            
    //$this->cmd = "mysqldump -q -X -u $user -p$pass $name -r $path$name.xml"; 
        

        function 
    backup() 
        { 
            
    passthru($this->cmd$retval); 

            if(!empty(
    $retval)) 
            { 
                
    print_r($retval); 
            } 
        } 

    // initilize mysqldump 
    $dump = new mysql_dump('root''root''newland_tours''./'); 
    // backup database 
    $dump->backup(); 
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles