Click to See Complete Forum and Search --> : SQL into MYSQL
k0r54
11-16-2004, 06:26 PM
Hi
I am using this below and it works fine
INSERT INTO logos1 ( Example, New, Title, Code )
SELECT animations.previewpath, dateadded, title, ID
FROM animations
in SQL i can use the INSERT INTO log.....
with the IN clause
i.e
INSERT INTO logos1 ( Example, New, Title, Code ) IN 'D:\APC.mdb'
SELECT animations.previewpath, dateadded, title, ID
FROM animations
how can i select the database in mysql to write the data into.
either that OR have php do it???
Many
Thanks
Adam
MstrBob
11-16-2004, 06:54 PM
Generally, you'd do something like this:
<?PHP
$connect = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_select_db('my_db', $connect);
?>
Before working performing MySQL queries. mysql_select_db allows you to select the proper Database.
k0r54
11-16-2004, 07:06 PM
Hi,
Sorry didn't quite explain it properly.
The animations database is a different database to logos database the IN clause works in access (SQL) but how do i get it to get the info from one database and put into another database on localhost
AND also a different username and password
So fari have this but it doesn't work
$connect1 = mysql_connect'localhost', 'mysql_user1', 'mysql_password1');
$insertdb = mysql_select_db('my_db1', $connect1);
$connect = mysql_connect'localhost', 'mysql_user', 'mysql_password');
mysql_select_db('my_db', $connect1);
$select = "INSERT INTO logos1 ( Example, New, Title, Code ) IN $insertdb
SELECT animations.previewpath, dateadded, title, ID
FROM animations";
$select_res = mysql_query($select,$connect);
Basicly the select is in my_db and it has to be inserted into my_db1
This works btw in SQL and also mysql without the IN clause so its just that bit!
Thanks
k0r54
k0r54
11-16-2004, 07:30 PM
OK
I have figured out how to get it into a different table
$select = "INSERT INTO my_db1.logos1 ( Example, New, Title, Code )
SELECT animations.previewpath, dateadded, title, ID
FROM animations"; //is in my_db
That works perfect providing the mysql_username and mysql_password is the same for both databases.
How will i do this if the my_db and my_db2 has different mysql_usernames????
Thanks
k0r54
Daniel T
11-16-2004, 08:19 PM
Simply have two active MySQL connections.$conn1 = mysql_connect("localhost", $user1, $pass1);
$conn2 = mysql_connect("localhost", $user2, $pass2);
mysql_select_db($db1, $conn1);
mysql_select_db($db2, $conn2);
$a_query = mysql_query("<query here>", $conn1);
$another_query = mysql_query("<another query here>", $conn2);
mysql_close($conn1);
mysql_close($conn2);
k0r54
11-16-2004, 08:21 PM
will that work even though it is a single query?