943,748 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 791
  • PHP RSS
Nov 30th, 2008
0

PHP and MYSQL Connections

Expand Post »
Hello..
I couldnt find anything for this topic. I know how to connect to a mysql database and close the connection.But that means that for every script a connection should be established and closed.
Is this right and ok for big projects? About 200 concurrent users for example;
Having a single connection stored globally if this is possible but it must be (havent tried) is right? Wouldnt there be security issues or problems with getLastInsertedID ?
SO what is the best solution for handling connections;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Nov 30th, 2008
0

Re: PHP and MYSQL Connections

If you're thinking large scale you might want to start thinking about an ORM to handle your object model and connections. Doctrine, Propel and Creole are 3 of the bigger ORMs in PHP.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Nov 30th, 2008
0

Re: PHP and MYSQL Connections

Thank you for the reply..
But whats the logic behind them?
You didnt answer my questions just gave me some solutions somehow
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Dec 1st, 2008
0

Re: PHP and MYSQL Connections

Hm, I think that the question was whether multiple visits on a database-driven site would be handled well, because each php page, which requires data from the db, would initiate a new sql session as well in order to insert, update or retrieve.
The solution is called persistent link and PHP supports it.
Here is some information on it.
http://bg2.php.net/mysql_pconnect
http://bg2.php.net/manual/en/feature...onnections.php

In theory this would minimize number of connections, however there are discussions whether this method is secure or not.
Also, many host service providers do not allow using persistent connections due to being afraid because of uncertainties how this method may be exploited by malicious users.

If I am not mistaking though, if you use includes for mysql authentication, and you do not close the connection on each querry, only one connection per session is created. In general, a user browsing your website will have 1 connection during his browsing session, until his session expires, or he closes his browser.

As for the ORM's I am not 100% sure they will minimize connection to database, unless they serve as some kind of middle-level mediator between the front end and the database. E.g. you can have multiple requests to the ORM from an on-line application, which are synthesized to a single connection from the ORM to the database. I have to read on the ORM's though...
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Dec 1st, 2008
0

Re: PHP and MYSQL Connections

Thank you for your answer! Persitent connections i searched for them and i see that there is a debate ...Anyways thank you for the answers.I though i was missing something..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
parhs is offline Offline
8 posts
since Oct 2008
Dec 2nd, 2008
0

Re: PHP and MYSQL Connections

Hi body
i want to learn php can you help me?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
pkpandit is offline Offline
1 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php controlling checkbox
Next Thread in PHP Forum Timeline: Initial Values





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC