The PHP Code:
<?php
//Server Information
$servername = "localhost";
$dbusername = "USERNAME";
$password = "TOTALLYSECUREPASSWORD";
$dbname = "DEFINITELYADATABASE";
//Query Information
$guid = $_POST['GUID'];
$username = $_POST['USERNAME'];
$admin_username = $_POST['ADMIN_USERNAME'];
$ban_reason = $_POST['BAN_REASON'];
$ip = $_POST['IP'];
//Create Connection
$connection = mysqli_connect($servername, $dbusername, $password, $dbname);
//Check the Connection
if ($connection->connect_error){
die("Connection failed: " . $connection->connect_error);
}
//$sql = "SELECT DATE, DBUSERNAME, GUID, IP, USERNAME, BAN_REASON FROM bans";
//$result = $connection->query($sql);
$sql = "SELECT * FROM bans WHERE";
$types = json_decode($_POST['QUERY_TYPE'], true);
if (in_array("query_admin_username", $types)) {
$sql = $sql . " DBUSERNAME = " . "\"" . $admin_username . "\"" . " &&";
}
if (in_array("query_guid", $types)) {
$sql = $sql . " GUID = " . "\"". $guid . "\"" . " &&";
}
if (in_array("query_ip", $types)) {
$sql = $sql . " IP = " . "\"" . $ip . "\"" . " &&";
}
if (in_array("query_username", $types)) {
$sql = $sql . " USERNAME = " . "\"" . $username . "\"" . " &&";
}
if (in_array("query_ban_reason", $types)) {
$sql = $sql . " BAN_REASON = " . "\"" . $ban_reason . "\"" . " &&";
}
$sql_query = substr($sql, 0, -3);
echo ($sql_query);
$result = $connection->query($sql_query);
while ($connection->query($sql_query)) {
}
if (!$result) {
die("Invalid Query: " . mysqli_error());
}
$row = $result->fetch_array(MYSQLI_NUM);
while ($row = mysqli_fetch_assoc($result)) {
echo ($row);
}
mysqli_close($connection);
?>
As weird as all that looks, it works just how I want it to (I think).
My issue:
I want to be able to get the data from each row and export it as one large String, something along the lines of:
[DATE] DBUSERNAME banned USERNAME (GUID / IP) for BAN_REASON.
I just have absolutely no idea how to go about this. I've tested the Query and it's returning everything it should, however I was using "echo ($row[0])" etc to display them, which is pretty impractical if it's going to return a large amount of rows.
Sorry if something doesn't make sense, my brain is fried at the moment. Please let me know if I forgot anything.
You could concatenate the columns like this if the rest of your script works:
SELECT CONCAT('[',DATE,'] ',DBUSERNAME,' banned ',USERNAME,'(',COALESCE(GUID, IP),),') for ', BAN_REASON) AS your_columns_in_one_line FROM your_table WHERE .....;
See this link for reference to CONCAT
Related
I have re-written this question because of all the down votes and it would seem that either no one understood the question or was unwilling to help a newbie. So I'll as it this way: Can someone tell/show me why this code does not work? (500 error)
OR... at the very least point me in the right direction? I AM WILLING TO LEARN, I just don't know where to begin or who/where to learn from as I am not sure what to even ask other than how do you run multiple "else" statements... that however left me more confused than I already am though!
Any "HELP" would be greatly appreciated!
<?php
$servername = "localhost";
$username = "****";
$password = "***";
$dbname = "***";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$bname = $_POST['bname'];
$baddress = $_POST['baddress'];
$bcity = $_POST['bcity'];
$bstate = $_POST['bstate'];
$zipcode = $_POST['zipcode'];
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Login FROM `USERS` WHERE Business_Name = '" . $_POST["bname"] . "' AND Business_Address = '" . $_POST["baddress"] . "' AND Business_State = '" . $_POST["bstate"] . "' AND Business_Zip = '" . $_POST["zipcode"] . "' LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while ($row = $result->fetch_assoc())
{
echo "https://www.***.com/realsite.php?Login=" . $row["Login"] . "";
}
}
else
{
$sql = "SELECT Login FROM `DATA` WHERE Business_Name = '" . $_POST["bname"] . "' AND Business_Address = '" . $_POST["baddress"] . "' AND Business_State = '" . $_POST["bstate"] . "' AND Business_Zip = '" . $_POST["zipcode"] . "' LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while ($row = $result->fetch_assoc())
{
echo "https://www.***.com/demo.php?Login=" . $row["Login"] . "";
}
}
else
{
$sql = "INSERT INTO `DATA` (Business_Name, Business_Address, Business_City, Business_State, Business_Zip)
SELECT '$bname', '$baddress', '$bcity', '$bstate', '$zipcode' FROM (SELECT 1) t
WHERE NOT EXISTS (SELECT Login, Business_Name,Business_Address FROM `DATA` WHERE Business_Name='$bname' AND Business_Address='$baddress')";
if (mysqli_query($conn, $sql))
{
echo "<a href='https://www.servedwell.com/realsite.php?Login=" . $row["Login"] . "'>LINK</a>";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
mysqli_close($conn);
}
?>
Credit goes to #Ancaron for properly formatting code and correcting a syntax error. Final posted code works fine.
I duplicated a folder full of scripts and edited the contents.
ex: /scripts -> /script-new
When I run a php script from this new file I seem to be having some weird issues.
php -f /scripts-new/pulldata.php
When I do this it seems to be using some variables from the old script that I have changed in the code.
/scripts/pulldata.php
$dbtable = "validclickvc";
/scripts-new/pulldata.php
$dbtable = "valid_click_ads";
Here is the mysql command that I am running
$sql = "INSERT INTO " . $dbtable . " ( COLUMN_NAMES ) " . " VALUES ( COLUMN_VALUES )";
And in my error log:
Error: INSERT IGNORE INTO validclickvc VALUES ( '--' )
What might be causing this?
EDIT:
Here is the whole script if it helps!
<?php
// Set some variables to connect to the FTP
$yesterday = date("Ymd", strtotime( '-1 days' ));
$filename = "vc_report_" . $yesterday . ".csv";
$sourcefile = "/***/" . $filename;
$localfile = "php://output";
$ftpserver = "***";
$ftpusername = "***";
$ftppassword = "***";
// Set some variabled to connect to rhe database
$dbhost = "***";
$dbname = "***";
$dbtable = "valid_click_ads";
$dbusername ="***";
$dbpassword = "***";
$fielddelimiter = ",";
$linedelimiter = "\r\n";
// Try to connect to the ftp server
$conn = ftp_connect($ftpserver) or die("Could not connect");
echo "Connected to FTP. \n";
// Try to login to the ftp server
if (ftp_login($conn, $ftpusername, $ftppassword)) {
echo "Logged in to FTP. \n";
} else {
echo "FTP login unsuccessful. \n";
}
ob_start();
// Try to open download today's report
$file = ftp_get($conn, $localfile, $sourcefile, FTP_BINARY);
if ($file) {
$csvcontent = ob_get_contents();
echo "File read successfully. \n";
} else {
echo "File was not read successfully. \n";
}
// Close the file and the connection to the FTP
ftp_close($conn);
echo "File and connection to the FTP closed. \n";
// Connect to the database
$con = mysqli_connect($dbhost, $dbusername, $dbpassword, $dbname);
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
} else {
echo "Connected to database. \n";
}
// Set row counter
$rows = 0;
// Set first
$first = true;
// Separate data by line
$lines = explode(PHP_EOL, $csvcontent);
// Insert lines of data
foreach ($lines as $line) {
if (!$first) {
$linearray = explode($fielddelimiter, $line);
print_r ($linearray);
$source_tag = $linearray[1];
if ( strpos( $source_tag, 'phone' ) !== false ) {
$source = "Smart Phone";
} else if ( strpos( $source_tag, 'desktop' ) !== false ) {
$source = "Desktop";
} else {
$source = "";
}
if ( $linearray[14] == "N/A" ) {
$tq = -1;
} else {
$tq = $linearray[14];
}
$sql = "SELECT affiliate_id, id, campaign_id, group_id, user_id, website_id FROM keywords WHERE affiliate_id = " . $linearray[7];
$result = $con->query($sql);
if ( $row = $result->fetch_assoc() ) {
$keyword_id = $row[ 'id' ];
$group_id = $row[ 'group_id' ];
$campaign_id = $row[ 'campaign_id' ];
$user_id = $row[ 'user_id' ];
$website_id = $row[ 'website_id' ];
} else {
$keyword_id = "";
$group_id = "";
$campaign_id = "";
$user_id = "";
$website_id = "";
}
$sql = "INSERT IGNORE INTO " . $dbtable . " ( market, source, device, searches, impressions, clicks, revenue, tq, website_id, user_id, campaign_id, group_id, affiliate_id, keyword_id ) " . " VALUES ( '" . $linearray[5] . "', " . $source . "', " . $linearray[4] . "', " . $linearray[8] . "', " . $linearray[9] . "', " . $linearray[10] . "', " . $linearray[12] . "', " . $tq . "', " . $website_id . "', " . $user_id . "', " . $campaign_id . "', " . $group_id . "', " . $affiliate_id . "', " . $keyword_id . "' )";
echo $sql;
if ($con->query($sql) === TRUE) {
$rows++;
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
} else {
$first = false;
}
}
$con->close();
echo "Inserted a total of " . $rows . " records.\n"
?>
Hi I have a table that records details which then after the record is saved I can use the link to update the diary. one field is a simple Job reference, the second is basically all the rest, name address etc inserted into a memo field in the diary, this is what I've come up with can I have some guidance please.
<?php
//record identifier date format 0000-00-00 same as server
$Dt = $_REQUEST['DT'];
// text output for appontment
$A = $_REQUEST['A'];
$B = $_REQUEST['B'];
$C = $_REQUEST['C'];
$D = $_REQUEST['D'];
$E = $_REQUEST['E'];
$F = $_REQUEST['F'];
$G = $_REQUEST['G'];
$H = $_REQUEST['H'];
$I = $_REQUEST['I'];
$J = $_REQUEST['J'];
$K = $_REQUEST['K'];
$L = $_REQUEST['L'];
$M = $_REQUEST['M'];
$N = $_REQUEST['N'];
// field names to reference
$APP = $_REQUEST['P'];
$JD = $_REQUEST['Q'];
// Field content
$JN = $_REQUEST['JID'];
$Desc = $"" . $A . "" . $B . " " . $C . ". " . $D . ", " . $E . " " . $F . " " . $G . " TF " . number_format($H,0, $decimal_point,"") . " " . $I . ", " . $J . " Walls, " . number_format($K,0, $decimal_point,"") . "Beds. " . $J . " " . $K . " boiler, with " . number_format($L,0, $decimal_point,"") . " radiators. notes " . $M . " observations " . $N . "";
?>
<?php
$servername = "localhost:3306";
$username = "xxxdjw";
$password = "xxxxxx";
$dbname = "xxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE masterdiary SET $APP ='$JN', $JD = '$Desc' WHERE date = '$dt'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
Or would it be easier to try and write a trigger?
It is advisable to use trigger for this
Sample trigger given below
CREATE
TRIGGER blog_after_insert AFTER INSERT
ON blog
FOR EACH ROW BEGIN
IF NEW.deleted THEN
SET #changetype = 'DELETE';
ELSE
SET #changetype = 'NEW';
END IF;
INSERT INTO audit (blog_id, changetype) VALUES (NEW.id, #changetype);
END$$
Trying to pull data out of a basic phpmyadmin database.
The code below pulls the data correctly (Commented out section verify).
I can write it to the screen and display it. (Not needed just testing)
Trying to insert it into another database however and it fails.
I've discovered that the while loops for inserting do not run. Although I can not find out why.
It's a basic localhost database (Testing right now) So the connect data is just temporary.
Any assistance is greatly appreciated
Thanks.
<?php
/*
Connect to database
*/
$webhost = 'localhost';
$webusername = 'root';
$webpassword = '';
$webdbname = 'transfertest';
$webcon = mysqli_connect($webhost, $webusername, $webpassword, $webdbname);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*
*
*/
$questions = mysqli_query($webcon, "SELECT * FROM questions");
$scenarios = mysqli_query($webcon, "SELECT * FROM scenarios");
$results = mysqli_query($webcon, "SELECT * FROM results");
$employees = mysqli_query($webcon, "SELECT * FROM employees");
/*
* These while loops display the content being pulled from the database correctly.
while ($row = mysqli_fetch_array($questions)) {
echo $row['questionID'] . " : " . $row['question'] . " : " . $row['answers'];
echo "</br>";
}
while ($row = mysqli_fetch_array($scenarios)) {
echo $row['scenarioID'] . " : " . $row['scenarioTitle'] . " : " . $row['scenarioInformation'];
echo "</br>";
}
while ($row = mysqli_fetch_array($results)) {
echo $row['employeeID'] . " : " . $row['scenarioID'] . " : " . $row['questionID'] . " : " . $row['answers'] . " : " . $row['correct'];
echo "</br>";
}
while ($row = mysqli_fetch_array($employees)) {
echo $row['employeeID'] . " : " . $row['firstName'] . " : " . $row['lastName'] . " : " . $row['email'] . " : " . $row['password'];
echo "</br>";
}
*/
/* //////////////////////////////////////////////////////////////////////////
Connect to database
*/
$mobhost = 'localhost';
$mobusername = 'root';
$mobpassword = '';
$mobdbname = 'exampletransfer';
$mobcon = mysqli_connect($mobhost, $mobusername, $mobpassword, $mobdbname);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/*
*
*/
while ($row = mysqli_fetch_array($questions)) {
mysqli_query($mobcon, "INSERT INTO questions (questionID, question, answers) VALUES (" . $row['questionID'] . ", " . $row['question'] . ", " . $row['answers'] . ")");
}
while ($row = mysqli_fetch_array($scenarios)) {
mysqli_query($mobcon, "INSERT INTO scenarios (scenarioID, scenarioTitle, scenarioInformation) VALUES (" . $row['scenariosID'] . ", " . $row['scenarioTitle'] . ", " . $row['scenarioInformation'] . ")");
}
while ($row = mysqli_fetch_array($results)) {
mysqli_query($mobcon, "INSERT INTO results (employeeID, scenarioID, questionID, answers, correct) VALUES (" . $row['employeesID'] . ", " . $row['scenariosID'] . ", " . $row['questionID'] . ", " . $row['answers'] . ", " . $row['correct'] . ")");
}
while ($row = mysqli_fetch_array($employees)) {
mysqli_query($mobcon, "INSERT INTO employees (employeeID, firstName, lastName, email, password) VALUES (" . $row['employeesID'] . ", " . $row['firstName'] . ", " . $row['lastName'] . ", " . $row['email'] . ", " . $row['password'] . ")");
}
/*
Close Connections
*/
mysqli_close($webcon);
mysqli_close($mobcon);
/*
* Error code:
Notice: Undefined index: scenariosID on line 75
Notice: Undefined index: employeesID on line 78
Notice: Undefined index: scenariosID on line 78
Notice: Undefined index: employeesID on line 81
*/
?>
The problem is that you close your $webcon connection and then you try to read from it ^^
You try to do this... Thats not possible ;)
Prepare query mysqli_query($webcon, "SELECT * FROM questions");
Close connection <<< after that i cant read data
Read data
Try this please.
<?php
/**
* Connect to database
*/
$webhost = 'localhost';
$webusername = 'root';
$webpassword = '';
$webdbname = 'transfertest';
$webcon = mysqli_connect($webhost, $webusername, $webpassword, $webdbname);
if (mysqli_connect_errno())
{
echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
}
/**
* Queries for reading
*/
$questions = mysqli_query($webcon, 'SELECT * FROM `questions`');
$scenarios = mysqli_query($webcon, 'SELECT * FROM `scenarios`');
$results = mysqli_query($webcon, 'SELECT * FROM `results`');
$employees = mysqli_query($webcon, 'SELECT * FROM `employees`');
/**
* Connect to database
*/
$mobhost = 'localhost';
$mobusername = 'root';
$mobpassword = '';
$mobdbname = 'exampletransfer';
$mobcon = mysqli_connect($mobhost, $mobusername, $mobpassword, $mobdbname);
if (mysqli_connect_errno())
{
echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
}
/**
* Insert data from old database
*/
// questions
while ($row = mysqli_fetch_array($questions))
{
// escape your strings
foreach($row as $key => $val)
{
$row[$key] = mysqli_real_escape_string($mobcon, $row[$key]);
}
mysqli_query($mobcon, "INSERT INTO `questions` (`questionID`, `question`, `answers`) VALUES ('" . $row['questionID'] . "', '" . $row['question'] . "', '" . $row['answers'] . "');");
}
// scenarios
while ($row = mysqli_fetch_array($scenarios))
{
// escape your strings
foreach($row as $key => $val)
{
$row[$key] = mysqli_real_escape_string($mobcon, $row[$key]);
}
mysqli_query($mobcon, "INSERT INTO `scenarios` (`scenarioID`, `scenarioTitle`, `scenarioInformation`) VALUES ('" . $row['scenariosID'] . "', '" . $row['scenarioTitle'] . "', '" . $row['scenarioInformation'] . "');");
}
// results
while ($row = mysqli_fetch_array($results))
{
// escape your strings
foreach($row as $key => $val)
{
$row[$key] = mysqli_real_escape_string($mobcon, $row[$key]);
}
mysqli_query($mobcon, "INSERT INTO `results` (`employeeID`, `scenarioID`, `questionID`, `answers`, `correct`) VALUES ('" . $row['employeesID'] . "', '" . $row['scenariosID'] . "', '" . $row['questionID'] . "', '" . $row['answers'] . "', '" . $row['correct'] . "');");
}
// employees
while ($row = mysqli_fetch_array($employees))
{
// escape your strings
foreach($row as $key => $val)
{
$row[$key] = mysqli_real_escape_string($mobcon, $row[$key]);
}
mysqli_query($mobcon, "INSERT INTO `employees` (`employeeID`, `firstName`, `lastName`, `email`, `password`) VALUES ('" . $row['employeesID'] . "', '" . $row['firstName'] . "', '" . $row['lastName'] . "', '" . $row['email'] . "', '" . $row['password'] . "');");
}
/*
Close Connections
*/
mysqli_close($mobcon);
mysqli_close($webcon);
Pending it's on the same server and using the same username and password:
// Create a new MySQL database connection
if (!$con = mysql_connect('localhost', $username, $password)) {
die('An error occurred while connecting to the MySQL server!<br/>' . mysql_error());
}
if (!mysql_select_db($database)) {
die('An error occurred while connecting to the database!<br/>' . mysql_error());
}
// Create an array of MySQL queries to run
$sql = array(
'DROP TABLE IF EXISTS `exampletransfer.questions`;',
'CREATE TABLE `exampletransfer.questions` SELECT * FROM `transfertest.questions`'
);
// Run the MySQL queries
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!mysql_query($query)) {
die('A MySQL error has occurred!<br/>' . mysql_error());
}
}
}
If using MySQLi instead of MySQL:
// Create a new MySQL database connection
if (!$con = new mysqli('localhost', $username, $password, $database)) {
die('An error occurred while connecting to the MySQL server!<br/>' . $con->connect_error);
}
// Create an array of MySQL queries to run
$sql = array(
'DROP TABLE IF EXISTS `exampletransfer.questions`;',
'CREATE TABLE `exampletransfer.questions` SELECT * FROM `transfertest.questions`'
);
// Run the MySQL queries
if (sizeof($sql) > 0) {
foreach ($sql as $query) {
if (!$con->query($query)) {
die('A MySQL error has occurred!<br/>' . $con->error);
}
}
}
$con->close();
Hi I have write a code that can copy database table from one sever to another but the record of each table did not copy how to write a function that can copy tables and each record from one db server to another?
here's my sample code:
<?php
$dbNewDB = 'newdb';
$dbNewUser = 'newroot';
$dbNewUserPswd = 'newpass';
$dbConnect = mysql_connect('localhost', 'root', 'mypassword') or die('Couldn\'t connect to MySql:'.mysql_error());
$dbNewConnect = mysql_connect('localhost', $dbNewUser, $dbNewUserPswd) or die('Couldn\'t connect to MySql:'.mysql_error());
$sqlStatement = "SHOW TABLES FROM olddb";
$result = mysql_query($sqlStatement,$dbConnect) or die('Unable to get tables: '.mysql_error());
while($row = mysql_fetch_row($result))
{
//Drop table if exist
$sqlStatement = "DROP TABLE IF EXISTS " . $dbNewDB . "." . $row[0];
mysql_query($sqlStatement,$dbNewConnect) or die("Failed to delete: " . mysql_error());
//Create new table
$sqlStatement = "CREATE TABLE " . $dbNewDB . "." . $row[0] . " LIKE olddb." . $row[0];
echo "$sqlStatement [" . __METHOD__ . "]";
mysql_query($sqlStatement,$dbNewConnect)or die("Failed to create: ". mysql_error());
//Insert data
$sqlStatement = "INSERT INTO " . $dbNewDB . "." . $row[0] . " SELECT * FROM " . $dbNewDB . "." . $row[0];
echo "$sqlStatement [" . __METHOD__ . "]";
mysql_query($sqlStatement,$dbNewConnect)or die("Table copy failed: ".mysql_error());
echo "$row[0] copy done. [" . __METHOD__ . "]";
}
mysql_free_result($result);
mysql_close($dbConnect);
mysql_close($dbNewConnect);
?>
my code is already functional All i want to fixed to copy the records of each tables.
Any idea?or help?
Thank you!
You can dump the whole database in SQL format like this:
mysqldump --user=root --password=whatever --databases dbtest --opt --quote-names --complete-insert > testbkup.sql
Then you can import it back like this:
mysql -u root -p whatever dbtest < testbkup.sql
(Note: user = root, password = whatever, dbtest is your database.)
Just saying.
I found these script working, you can try these:
<?php
$connect2 = mysql_connect("localhost", "root", "");
$database1 = "test1"; // destination database
mysql_select_db($database1, $connect2);
set_time_limit(0);
$database = 'dev_loribonn'; //original database
$connect = mysql_connect("localhost", "root", "");
mysql_select_db($database, $connect);
$tables = mysql_query("SHOW TABLES FROM $database");
while ($line = mysql_fetch_row($tables)) {
$tab = $line[0];
mysql_query("DROP TABLE IF EXISTS $database1.$tab");
mysql_query("CREATE TABLE $database1.$tab LIKE $database.$tab") or die(mysql_error());
mysql_query("INSERT INTO $database1.$tab SELECT * FROM $database.$tab");
echo "Table: <b>" . $line[0] . " </b>Done<br>";
}
?>
Your insert statement looks off. Trying to insert into $dbNewDB with your values coming from dbNewDB. You have to turn to the old database. Below I am building two stings for the insert. $string1 = '(col1name, col2name...,)' $string2 = '(val1-1, val1-2, ...), (val2-1, val2-2,...), ...' for "INSERT INTO table $string1 VALUES $string2"
//Insert data
$sql2 = "SELECT * FROM " . $row[0];
$r = mysql_query($sql, $bConnect);
$string1 = '('; $arr = array();
while ($irow = mysql_fetch_assoc($r)) {$arr[] = $irow;}
foreach($irow as $k=>$v)
{
$string1 .= "$k,";
}
$string1 = substr($string1, 0, -1) //lose last comma
$string1 .= ')';
$string2 = array_reduce($f, $arr);
$string2 = substr($string2, 0, -1) //lose last comma
$sqlStatement = "INSERT INTO " . $dbNewDB . "." . $row[0] . " $string1 VALUES $string2";
echo "$sqlStatement [" . __METHOD__ . "]";
mysql_query($sqlStatement,$dbNewConnect)or die("Table copy failed: ".mysql_error());
echo "$row[0] copy done. [" . __METHOD__ . "]";
declare $f elsewhere
$f = function($b, $x) {$a = ' ('; foreach($x as $v) {$a .= "'$v',";} $a = substr($a, 0, -1); $a .= ')'; return "$b $a,";}
You can use sql yog to transfer the tables to different host without writing code in php .