473,408 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Making mysql_connect more efficient in my script

LRW
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("priceretail", $connection2) or die ("Couldn't
select database.");
$sql2 = "SELECT dbname FROM productlist WHERE ((accountid =
'printingautomation') OR (accountid = '$accountid')) AND dbname =
'$sel_typeproduct'";

--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("priceretail", $connection3) or die ("Couldn't
select database.");
$sql3 = "SELECT companyid FROM $sel_typeproduct 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
Jul 19 '05 #1
0 932

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
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 =...
7
by: Frogman | last post by:
Hi, I am new to php and I'm testing php connectivity to mysql. I created a php script using the php.net sample. The script uses the mysql_connect method and when I execute it I get the error: ...
10
by: Alvaro G Vicario | last post by:
I need that my script retrieves data from two different databases so I use mysql_connect() to open two connections. I have only one server, user and password, just two different databases....
4
by: Andrew Clark | last post by:
Hello, I am having trouble connecting to my server with mysql_connect(). I can connect via the command line on the server and with phpMyAdmin over our network, but not though mysql_connect()....
2
by: Sugapablo | last post by:
I have a small test script connecting to a MySQL database. It seems to work, unless I try to use the resource link identifier returned by mysql_connect(); This works and returns all the rows in...
7
by: avenpace | last post by:
Hi, I got error when using mysql_connect function in my php script. If i set the db host to localhost, it give me that error altough all the user and password that I wrote is true(I can login...
1
by: hugo | last post by:
Hello people, There is a problem is that mysql_connect() somehow caches last sessions IP and is not using the one which you put into host place. Has anyone made mysql_connect() from php to...
14
by: farhan | last post by:
Hi, Please divert me if this is not the right group to be posting this question. I am a Linux client trying to connect to a mysql windows server via php, upon hitting the mysql_connect line...
7
by: criveraf | last post by:
Hi there, I wasn't sure where to put this question, since it deals with both PHP and MySQL. I apologize if this is not the correct forum for this. I am working with a simple PHP application...
2
by: Ralf Seliger | last post by:
Hi, I hope someone here has a clue as to what is going on since I am completely baffled by the following: I'm working with a PHP/MySQL-web application called Moodle. When this application is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.