/    Sign up×
Community /Pin to ProfileBookmark

SQL into MYSQL

Hi

I am using this below and it works fine

[CODE]
INSERT INTO logos1 ( Example, New, Title, Code )
SELECT animations.previewpath, dateadded, title, ID
FROM animations
[/CODE]

in SQL i can use the INSERT INTO log…..

with the IN clause

i.e

[CODE]
INSERT INTO logos1 ( Example, New, Title, Code ) IN ‘D:APC.mdb’
SELECT animations.previewpath, dateadded, title, ID
FROM animations
[/CODE]

how can i select the database in mysql to write the data into.

either that OR have php do it???

Many
Thanks
Adam

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobNov 17.2004 — Generally, you'd do something like this:

[code=php]
<?PHP
$connect = mysql_connect('localhost', 'mysql_user', 'mysql_password');
mysql_select_db('my_db', $connect);
?>
[/code]


Before working performing MySQL queries. mysql_select_db allows you to select the proper Database.
Copy linkTweet thisAlerts:
@k0r54authorNov 17.2004 — 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

[code=php]
$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);
[/code]


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
Copy linkTweet thisAlerts:
@k0r54authorNov 17.2004 — OK

I have figured out how to get it into a different table

[CODE]
$select = "INSERT INTO my_db1.logos1 ( Example, New, Title, Code )
SELECT animations.previewpath, dateadded, title, ID
FROM animations"; //is in my_db
[/CODE]


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
Copy linkTweet thisAlerts:
@Daniel_TNov 17.2004 — Simply have two active MySQL connections.[code=php]$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);[/code]
Copy linkTweet thisAlerts:
@k0r54authorNov 17.2004 — will that work even though it is a single query?
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...