Hi i have a php script that retrieves all data from one database to be transferred to another database. The problem is that the database I am retrieving has 2,778 total rows and after i run my script the new database has 2,658 total rows. Whats going on?

Here is the php code.

<?php
error_reporting(E_ALL);
/*
First of all, connect to the kmedianet_main table and retrieve all files to be transferred
Uses the PEAR DB class,
*/
require("./DB.php");

$dbun = "example"; // database username
$dbpas = "example"; // database password
$dbname = "example"; // database name
$dsn = "mysql://$dbun:$dbpas@localhost/$dbname";
$conn =& DB::connect($dsn);
if (DB::isError ($conn))
die ("Cannot connect: " . $conn->getDebugInfo () . "\n");
// echo "connected: <Br>";
// echo "got cats: <Br>";
/*
fetch all data from the main table and prepare it for entry into mp3s
*/
$raw_data = array();
$q = 'SELECT users.id, users.username, users.password, users.email, users.ip, users.reg_date, users_profile.fname, users_profile.lname, users_profile.gender, users_profile.birthday, users_profile.country, users_profile.age FROM `users`,`users_profile` WHERE users.id = users_profile.mid';
$r = $conn->query($q);
if(DB::isError($r)) // kill on errors to ensure corrupt data is prevented from entering database
{
die("Error loading from main table: " . $r->getDebugInfo());
}

$x = 0; // initiate incrementer
while($row=$r->fetchRow())
{
// data straight from database
$raw_data[$x] = $row[0];
$raw_data[$x] = $row[1];
$raw_data[$x] = $row[2];
$raw_data[$x] = $row[3];
$raw_data[$x] = $row[4];
$raw_data[$x] = $row[5];
$raw_data[$x] = $row[6];
$raw_data[$x] = $row[7];
$raw_data[$x] = $row[8];
$raw_data[$x] = $row[9] . " 00:00:00";
$raw_data[$x] = $row[10];
$raw_data[$x] = $row[11];

//$raw_data[$x] = strtotime
$join = strtotime($raw_data[$x]);
$raw_data[$x] = date("Y-m-d 00:00:00",$join);
$x++; // increase incrementor so that data is not overwritten
}
//echo "<pre>";
//print_r($raw_data);
//echo "</pre>";
// echo "sorted data: <Br>";
/*
connection with the _main database is over. Now connect to the _music database
*/
$dbun = "example"; // database username
$dbpas = "example"; // database password
$dbname = "example"; // database name
$dsn = "mysql://$dbun:$dbpas@localhost/$dbname";
$conn =& DB::connect ($dsn);
if (DB::isError ($conn))
die ("Cannot connect to kmediacom_music: " . $conn->getDebugInfo () . "\n");
// echo "connected to 2nd database: <Br>";

/*
Now add each row of data to the new database
*/
foreach($raw_data as $file)
{
$q = ""; // reset the query string for each iteration
$q = "INSERT IGNORE INTO `users` (user_id, user_name, password, email, first_name, last_name, sex, age, country, usr_status, doj, dob) VALUES ";
$q .= "(";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'".$file."',";
$q .= "'Ok',";
$q .= "'".$file."',";
$q .= "'".$file."'";
$q .= ")"; // construct the INSERT query
$r = $conn->query($q);
//if(DB::isError($r))
//  echo "Error inserting into new database on record" . $file . " : ". $r->getDebugInfo() . "<Br> $q";
}

// echo "inserted data into new database: <Br>";
?>

Because your script is inserting some rows without failing, I would suggest taking a look at your destination table and ensure that the columns are of appropriate length and type to handle the data you are trying to give it. For instance, you may be trying to stuff a varchar(50) into a varchar(40) which would result in the problems you're seeing.

-Andy

please also check, is it not problem of time out

Is not the time out becuase my php time out has no limit. Also if For instance, if I may be trying to stuff a varchar(50) into a varchar(40) which would result in the problems am not seeing then why has it copy other rows leaving some

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.