CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Exporting my databse from CCS

Print topic Send  topic

Author Message
codebang

Posts: 74
Posted: 01/24/2009, 4:52 AM

hello....

Well, first of all i want to thank everybody,for solving my last navigation problem.

Well i want to ask u if there is a way to export my whole database using CCS, by the click of a button.
as i will need the whole database.
second of all...how can i import it back to my original databse, with the new and old records....

Any ideas...

Thank u..

Salah Hafiz
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/24/2009, 9:29 AM

Hi.

Probably the easiest way is to do an exec() function from CCS.

eg:

exec("mysqldump –-user [user name] –-password=[password] [database name] > [dump file]");

You can get the user name and password from the CCS connections array.

To restore use the reverse mysql command to impoet the table or database.

Here is an article to describe it.

http://www.unixcities.com/mysql/mysqldump.html

Have fun

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
codebang

Posts: 74
Posted: 01/27/2009, 12:06 AM

thank u so, very much john.

Where exactly should i add this code.
in a button, or in an event. if u can give me an example...real example.
im planning of attaching to one of my add buttons after all transactions in the system are done...

So what do u think..

Thank you,
Salah
View profile  Send private message
damian

Posts: 838
Posted: 01/27/2009, 4:40 AM

here you go -
this creates a backup on loading the page and creates a link to the backup
please note it creates a new backup file every time its run so you might want to do a cleanup every now and again or you can modify to overwrite each time

create a folder called dbbackup and ensure you give full permissions
use notepad to create a file called exportdb.php and paste the following into it:

<html><head>  
<title>mySQL Database Backup</title></head>  
<body>  
<a href="dbbackup/  
  
<?php  
  
backup_my_tables('localhost','username','password,'database');     
     
 /* backup the db OR just a table */    
function backup_my_tables($host,$user,$pass,$name,$tables = '*')     
{     
    $myback = time();  
    echo $myback;     
    $link = mysql_connect($host,$user,$pass);     
    mysql_select_db($name,$link);     
         
    //get all of the tables     
    if($tables == '*')     
    {     
        $tables = array();     
        $result = mysql_query('SHOW TABLES');     
        while($row = mysql_fetch_row($result))     
        {     
            $tables[] = $row[0];     
        }     
    }     
    else    
    {     
        $tables = is_array($tables) ? $tables : explode(',',$tables);     
    }     
         
    //cycle through     
    foreach($tables as $table)     
    {     
        $result = mysql_query('SELECT * FROM '.$table);     
        $num_fields = mysql_num_fields($result);     
             
        $return.= 'DROP TABLE '.$table.';';     
        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));     
        $return.= "\n\n".$row2[1].";\n\n";     
             
        for ($i = 0; $i < $num_fields; $i++)      
        {     
            while($row = mysql_fetch_row($result))     
            {     
                $return.= 'INSERT INTO '.$table.' VALUES(';     
                for($j=0; $j<$num_fields; $j++)      
                {     
                    $row[$j] = addslashes($row[$j]);     
                    $row[$j] = ereg_replace("\n","\\n",$row[$j]);     
                    if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }     
                    if ($j<($num_fields-1)) { $return.= ','; }     
                }     
                $return.= ");\n";     
            }     
        }     
        $return.="\n\n\n";     
    }     
         
    //save file     
    $handle = fopen('dbbackup/'.$myback.'.sql','w+');     
    fwrite($handle,$return);     
    fclose($handle);     
}    
  
?>  
.sql">Download New Backup</a>  
</body>  
</html>

replace the variables from:
backup_my_tables('localhost','username','password,'database');

im sure you can work out how to get it into ccs and make the page restricted.... it took me long enough to serach this code, test it, modify etc.... over to you for the next step - please post your final solution if you run with this.

credit: most of the work was done here: http://davidwalsh.name/backup-mysql-database-php
and i just changed a couple of things to suit me....
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
jjrjr1


Posts: 942
Posted: 01/27/2009, 8:56 AM

Thanks Damian

Just curious why you would write all that code when

exec("mysqldump –-user [user name] –-password=[password] [database name] > [dump file]");

creates a MySql insertable file with all the table structure along with the data??

Let me know. I might have missed something and possibly need to really be using what you have.

Thanks

Have fun

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
damian

Posts: 838
Posted: 01/27/2009, 6:50 PM

hah! i didnt write it - just tested it and modified it a bit :)
many hosted servers do not give you access to mysqldump
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.