http://au2.php.net/function.mysql-query

mysql_query($query, $link_identifier);

Which commands require $link_identifier, thought there be a list on google but to no avia. :(

Thanks, Regards X

PS: There not required but its good practice you use the connection string after the query string.

I dont think there all applicable for example:

mysql_fetch_array($query, $connection)

I dont think that will work

Do you think its just better to drop the $connection when working on big projects?

I try to use the simple principles we first used when starting php (use the connection with the query), etc.

Thanks

Yep.. It doesn't.. mysql_fetch_array doesn't connect to the database. It just uses the result resource returned by mysql_query (which uses $link_identifier).
See this for example.

<?php
$con = mysql_connect("localhost","root");
mysql_select_db("test");
$query = "select * from test";
$result = mysql_query($query);
mysql_close($con);
while($row = mysql_fetch_array($result)) {
	print "<pre>";
	print_r($row);
	print "</pre>";
}
?>

Even though I have closed the connection before mysql_fetch_array, it still works.
Since its an optional parameter, I don't use it (big project or small).

Also you may want to note that the link identifier is not always optional. An example is if you wanted to connect to multiple accounts then that is when you will need to specify which account to find the database structure in. And to specify which database structure or account that is what the $link_identifier is for. But by default it uses the last connection opened. So as long as you only are only using the mysql_connect() function once you won't need to use the identifier.

Even with mysql_close, dosent require the $con variable, correct?

Just brought up another question, why does it still preform the query even though the connection has been closed? and if so what is the point of closing the connection then? if it still being accessed seems pointlessss :|

You got it wrong. It doesn't perform the query after the connection is closed. In the above example, it queries the table, closes the connection and then uses the result resource.
And yes, mysql_close also don't need $link_identifier.
As cwarn23 has mentioned already, if you are having multiple database connections in your script, then you need to mention $link_identifier to specify which database's table you want to query.

Have you guys ever required to link to multiple connections?
If so how often?

Trying to plan for the future, thanks!

Yeah.. In some applications, I had to connect to the supplier database and consumer database to show the supplier - consumer information.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.