Jump to content

table not copying


jakebur01

Recommended Posts

I am having trouble getting my table to drop and then create a new table based on another.

$connect = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name)or die("Couldn't select");

// Empty table
$query = "DROP TABLE IF EXISTS `jhearnsberger.books_copy`";
mysql_query($query);
$query = "CREATE TABLE IF NOT EXISTS `jhearnsberger.books_copy` SELECT * FROM `jhearnsberger.books`";
mysql_query($query);
$query = "DELETE FROM $db_name.$destable";
$result = mysql_query($query)or die("Couldn't delete");

// do the data import
$query = "load data infile \"$source_file\" INTO TABLE $destable FIELDS TERMINATED BY '|'";

$result = mysql_db_query($db_name, $query, $connect)
or die(mysql_error()); 

Link to comment
Share on other sites

And, what errors are you receiveg, if any. Which process does not execute? You should add error handling at every DB action.

 

<?php

$connect = mysql_connect($db_host,$db_user,$db_pass) or die(mysql_error());
mysql_select_db($db_name)or die("Couldn't select") or die(mysql_error());

// Empty table
$query = "DROP TABLE IF EXISTS `jhearnsberger.books_copy`";
mysql_query($query) or die($query."<br>".mysql_error());

$query = "CREATE TABLE IF NOT EXISTS `jhearnsberger.books_copy` SELECT * FROM `jhearnsberger.books`";
mysql_query($query) or die($query."<br>".mysql_error());

$query = "DELETE FROM $db_name.$destable";
mysql_query($query) or die($query."<br>".mysql_error());

// do the data import
$query = "load data infile \"$source_file\" INTO TABLE $destable FIELDS TERMINATED BY '|'";
mysql_db_query($db_name, $query, $connect) or die(mysql_error()); 

?>

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.