Forum Moderators: coopster

Message Too Old, No Replies

Accessing MySQL in user function

         

salewit

4:45 am on Mar 28, 2008 (gmt 0)

10+ Year Member



I'm fresh off the truck on user functions, and have run into a problem I can't figure out.

I have a PHP script that starts with an include:


<?php
include ("/home/initializedatabase.php");

## Process some database stuff here
$resultID = mysql_query("Select * from table1, etc",$linkID);

## Call a function
more_db_stuff(item$);

function more_db_stuff($item) {
$resultID2 = mysql_query("Select * from table2, etc",$linkID);
print "stuff";
}
?>

What is the best way to include the SAME database parameters inside AND outside of the function? I should also mention that the function will be inside a loop, so I don't think I want to continually initialize the DB on every iteration.

Thanks for the help, and sorry if I'm not making perfect sense.

jatar_k

2:13 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> include the SAME database parameters

I am not 100% sure what you mean, do you mean the $linkID? So just have your connection available everywhere in your script?

you don't actually need to specify the connection you want to use unless there is more than one, it uses the last opened connection by default.

salewit

4:54 pm on Mar 28, 2008 (gmt 0)

10+ Year Member



Yes I'm not sure 100% of what *I* mean either! I dropped the $linkID on the end and everything worked fine. Without knowing what I meant, you actually helped me out quite a bit! Thanks.

jatar_k

5:01 pm on Mar 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe, that's pretty funny, glad to help