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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.