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
https://forums.phpfreaks.com/topic/95670-table-not-copying/
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
https://forums.phpfreaks.com/topic/95670-table-not-copying/#findComment-489821
Share on other sites

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.