I'm working on some scripts someone else made, and it's littered with
repetitive mysql_connect's and mysql_select_db 's.
For example:
// MAKE SURE IT IS A VALID PRODUCT
$connection2 = mysql_connect(" localhost", "root") or die ("Couldn't
connect to the server.");
$db2 = mysql_select_db ("priceretai l", $connection2) or die ("Couldn't
select database.");
$sql2 = "SELECT dbname FROM productlist WHERE ((accountid =
'printingautoma tion') OR (accountid = '$accountid')) AND dbname =
'$sel_typeprodu ct'";
--SNIP--
// MAKE SURE IT IS A PRODUCT THAT HAS PRICING SET FOR IT
$connection3 = mysql_connect(" localhost", "root") or die ("Couldn't
connect to the server.");
$db3 = mysql_select_db ("priceretai l", $connection3) or die ("Couldn't
select database.");
$sql3 = "SELECT companyid FROM $sel_typeproduc t WHERE companyid
--SNIP--
Yes, it DOES say root in the script.
Here's what I'm wanting to do: make a script that contains the two
mysql_connect and mysql_select_db lines and then do a require() or
require_once() to call it. (And set up and use a different account
than root.)
Now, the questions:
Should I use require or require_once?
And is there a reason why the connection is established multiple times
that I don't understand? Can't it be established once at the top and
use new mysql_query's each time?
Thanks for any help!!
Liam
repetitive mysql_connect's and mysql_select_db 's.
For example:
// MAKE SURE IT IS A VALID PRODUCT
$connection2 = mysql_connect(" localhost", "root") or die ("Couldn't
connect to the server.");
$db2 = mysql_select_db ("priceretai l", $connection2) or die ("Couldn't
select database.");
$sql2 = "SELECT dbname FROM productlist WHERE ((accountid =
'printingautoma tion') OR (accountid = '$accountid')) AND dbname =
'$sel_typeprodu ct'";
--SNIP--
// MAKE SURE IT IS A PRODUCT THAT HAS PRICING SET FOR IT
$connection3 = mysql_connect(" localhost", "root") or die ("Couldn't
connect to the server.");
$db3 = mysql_select_db ("priceretai l", $connection3) or die ("Couldn't
select database.");
$sql3 = "SELECT companyid FROM $sel_typeproduc t WHERE companyid
--SNIP--
Yes, it DOES say root in the script.
Here's what I'm wanting to do: make a script that contains the two
mysql_connect and mysql_select_db lines and then do a require() or
require_once() to call it. (And set up and use a different account
than root.)
Now, the questions:
Should I use require or require_once?
And is there a reason why the connection is established multiple times
that I don't understand? Can't it be established once at the top and
use new mysql_query's each time?
Thanks for any help!!
Liam
Comment