I have two databases. I want to know if it's possible to use PHP to query the first Database and return a SQL file of multiple tables saved as a file in a temp folder. In the same script it would then connect to my second Database, drop the tables if they exist and replace them with the SQL file.
Any help or points in the right direction are greatly appreciated!
Using PHP to Query One DB and Insert Tables into Another
Moderator: General Moderators
Upon more research I dsicovered this, but it doesn't appear to be delivering the file to the folder:
Can anyone help me with this?
Code: Select all
<?php
$host = "sql.mydomain.com";
$user="XXXXX";
$pass="XXXXX";
$base="sql";
$conn = mysql_connect($host,$user,$pass);
mysql_select_db($base);
$tableName = 'products';
$backupFile = 'backup/products.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
mysql_close($conn);
?>Use PHP tags for php code, not Code!
I think you should use an absolute path there, maybe now the file is created relative to your database bin folder or something.
Be sure to read the docs about SELECT ... INTO OUTFILE, there are possible pitfalls in using it. For example the file should not exist.
I think you should use an absolute path there, maybe now the file is created relative to your database bin folder or something.
Be sure to read the docs about SELECT ... INTO OUTFILE, there are possible pitfalls in using it. For example the file should not exist.