dsaba Posted June 27, 2007 Share Posted June 27, 2007 I have a mysql db that I use with phpmyadmin I want to export my entire database, but in php code because I am transferring this data to another db which does not have access to phpmyadmin, so i need to do it via php code I can choose to dump the db with phpmyadmin with "none" selected and it shows me the sql but with a bunch of crap that will error the mysql_query() function for example: -- phpMyAdmin SQL Dump -- version 2.6.4-pl2 -- http://www.phpmyadmin.net -- -- Host: mysql3.freehostia.com -- Generation Time: Jun 27, 2007 at 05:42 PM -- Server version: 4.1.11 -- PHP Version: 4.4.4-8+etch1 -- -- Database: `geospa_index` -- -- -------------------------------------------------------- -- -- Table structure for table `comments` -- CREATE TABLE `comments` ( `commentid` int(255) NOT NULL auto_increment, `commentfileid` int(255) NOT NULL default '0', `commentfilegeneraltype` varchar(255) NOT NULL default '', `commentfilespecifictype` varchar(255) NOT NULL default '', `commentbyuserid` int(255) NOT NULL default '0', `comment` text NOT NULL, `commentusername` varchar(255) NOT NULL default 'Unknown', `commentuseremail` varchar(255) NOT NULL default 'Unknown', `commentifusermember` varchar(255) NOT NULL default '', `commentdatetime` varchar(255) NOT NULL default '', `commentdate` varchar(255) NOT NULL default '', `commentuserip` varchar(255) NOT NULL default '', `comment4userid` int(255) NOT NULL default '0', `commentuserlink` varchar(255) NOT NULL default '', `commenfilelink` varchar(255) NOT NULL default '', `commentneedstrans` varchar(255) NOT NULL default 'Yes', PRIMARY KEY (`commentid`), KEY `commentfileid` (`commentfileid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `comments` -- -- -------------------------------------------------------- -- -- Table structure for table `dictionary` -- CREATE TABLE `dictionary` ( `id` int(255) NOT NULL auto_increment, `english` varchar(255) collate utf8_bin NOT NULL default '', `hebrew` varchar(255) collate utf8_bin default NULL, `spanish` varchar(255) collate utf8_bin default I wish I could export it without the comment crap, I dont see an option to do that, and it doesn't have an option to export it via php code, I guess phpmyadmin is almostphpmyadmin really... How can I do it? All i want to do export the db in something I can use with the mysql_query() function in php -thank you Quote Link to comment Share on other sites More sharing options...
chigley Posted June 27, 2007 Share Posted June 27, 2007 Have you tried this? <?php $query = '-- phpMyAdmin SQL Dump -- version 2.6.4-pl2 -- http://www.phpmyadmin.net -- -- Host: mysql3.freehostia.com -- Generation Time: Jun 27, 2007 at 05:42 PM -- Server version: 4.1.11 -- PHP Version: 4.4.4-8+etch1 -- -- Database: `geospa_index` -- -- -------------------------------------------------------- -- -- Table structure for table `comments` -- CREATE TABLE `comments` ( `commentid` int(255) NOT NULL auto_increment, `commentfileid` int(255) NOT NULL default \'0\', `commentfilegeneraltype` varchar(255) NOT NULL default \'\', `commentfilespecifictype` varchar(255) NOT NULL default \'\', `commentbyuserid` int(255) NOT NULL default \'0\', `comment` text NOT NULL, `commentusername` varchar(255) NOT NULL default \'Unknown\', `commentuseremail` varchar(255) NOT NULL default \'Unknown\', `commentifusermember` varchar(255) NOT NULL default \'\', `commentdatetime` varchar(255) NOT NULL default \'\', `commentdate` varchar(255) NOT NULL default \'\', `commentuserip` varchar(255) NOT NULL default \'\', `comment4userid` int(255) NOT NULL default \'0\', `commentuserlink` varchar(255) NOT NULL default \'\', `commenfilelink` varchar(255) NOT NULL default \'\', `commentneedstrans` varchar(255) NOT NULL default \'Yes\', PRIMARY KEY (`commentid`), KEY `commentfileid` (`commentfileid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `comments` -- -- -------------------------------------------------------- -- -- Table structure for table `dictionary` -- CREATE TABLE `dictionary` ( `id` int(255) NOT NULL auto_increment, `english` varchar(255) collate utf8_bin NOT NULL default \'\', `hebrew` varchar(255) collate utf8_bin default NULL, `spanish` varchar(255) collate utf8_bin default'; $result = mysql_query($query) or die(mysql_error()); ?> Seems obvious, might work. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 chingley that will work if you encapsulate the creations into a variable Quote Link to comment Share on other sites More sharing options...
per1os Posted June 27, 2007 Share Posted June 27, 2007 mysqlDbLoadFromBackup.php <?php //Copyright Lawrence Truett and www.FluffyCat.com March 3, 2007 //this is the file you are loading your tables from $file = fopen("backup20070303.sql","w"); $line_count = load_backup_sql($file); fclose($file); echo "lines read: ".$line_count; function load_backup_sql($file) { $line_count = 0; $db_connection = db_connect(); mysql_select_db (db_name()) or exit(); $line_count = 0; while (!feof($file)) { $query = NULL; while (!feof($file)) { $query .= fgets($file); } if (NULL != $query) { $line_count++; mysql_query($query) or die("sql not successful: ".mysql_error()." query: ".$query); } } return $line_count; } function db_name() { return ("your_db_name_here"); } function db_connect() { $db_connection = mysql_connect("localhost", "your_mysql_id_here", "your_mysql_pw_here"); return $db_connection; } ?> Found at http://www.fluffycat.com/SQL/MySQL-Database-Backup-With-PHP/ Should get you what you want, the comment crap doesn't matter, if that is entered into mysql_query it will just be ignored. (or so I think) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.