|
-
Jul 28th, 2006, 03:57 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Is this database connection handling ok?
Hello guys,
I inherited a PHP application. In the db layer of the application, it has this function to connect to a mySql db.
[phpcode]
function getConn() {
return mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error());
}
[/phpcode]
This function gets called at the beginning of every db function in the dblayer class.
Beeing new to PHP, I do not know if this is handled well. There's no connection closing on PHP? or it's handled automatically by a connection pool that times out?
Thanks
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Jul 28th, 2006, 04:31 AM
#2
Re: Is this database connection handling ok?
Basically, all db connections are closed when the script terminates.
Also, mysql_connect() and the other DB connections tend to cache handles and return the same handle for the same request.
However, personally I think you should still keep the connection handle in the class and only call getConn() once.
(I also think you should use the MDB2 DB abstraction layer if you're using PHP4, and the DBO extension if you're using PHP5, but that's a different story.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 29th, 2006, 12:02 PM
#3
Fanatic Member
Re: Is this database connection handling ok?
Most code I know makes the connection at the start calls "actions" and closes leaning on the fact that you will mostly only want to talk tot he one database and therefore can get on with called mysql_query.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|