| | |
PHP and MYSQL Connections
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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;
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;
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.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
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...
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...
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
![]() |
Similar Threads
- Warning: mysql_fetch_assoc(): 2 is not a valid MySQL result resource (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource (PHP)
- PHP Dynamic Form HELP! (PHP)
- PHP MySQL problem (PHP)
- php results from form - stuck (PHP)
- unable to connect PHP with Mysql (PHP)
- MySQL Functions W/ Offline Languages (MySQL)
- I had a experience of a website coded in PHP (PHP)
Other Threads in the PHP Forum
- Previous Thread: php controlling checkbox
- Next Thread: Initial Values
| Thread Tools | Search this Thread |
# 5.2.10 ajax apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla ldap legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery oop open paypal pdf persist php problem provider query radio random recursion regex remote rss script search server sessions sms soap sockets source space spam sql syntax system table tutorial update upload url validator variable video web xml youtube






