is this bad practise?
Posted: Mon Jan 22, 2007 6:24 am
hi i have some standard php functions, that pull data from a database and spit out formatted html.
so first i have the base script:
then the fubar() function, described below, initialises the mysql connection, queries the dbase for the data, and outputs the formatted html...
but then i have another function, another_function_call(), which also inits a sql connection to the same database...
what i am wondering is if this is bad? it's almost like a nested mysql connection, for use of a better description.
i personally don't see anything wrong with it. but then again, if ive already initialised a sql connection, should i try use the same one? or is there no danger in my current approach?
so first i have the base script:
Code: Select all
<?php
include("functions/foo.php");
print_html_header();
fubar($table);
print_html_footer();
?>Code: Select all
// inside foo.php
...
function fubar($table)
{
$connection_A = mysql_connect(...);
//some code...
another_function_call();
mysql_close($connection_A);
}
...Code: Select all
// further down in foo.php
...
function another_function_call()
{
$connection_B = mysql_connect(...same database);
//do stuff
mysql_close($connection_B);
}
...i personally don't see anything wrong with it. but then again, if ive already initialised a sql connection, should i try use the same one? or is there no danger in my current approach?