Jump to content

export php code with mysql phpmyadmin! how?


dsaba

Recommended Posts

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

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.

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.