Jump to content

MySQL connection


orange08

Recommended Posts

The most commonly used is mysql_connection.

 

mysql_pconnect establishes a persistent connection. If you don't need one (such as a website that is mostly HTML files or PHP files that don't call the db) then you don't need to use it.

 

mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

 

If you do use mysql_pconnect. You only need to call it once for the session. That's the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

 

Please read this link for more info:  PHP: Persistent DB Connection.

Link to comment
Share on other sites

The most commonly used is mysql_connection.

 

mysql_pconnect establishes a persistent connection. If you don't need one (such as a website that is mostly HTML files or PHP files that don't call the db) then you don't need to use it.

 

mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

 

If you do use mysql_pconnect. You only need to call it once for the session. That's the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

 

Please read this link for more info:  PHP: Persistent DB Connection.

 

as a newbie, i don't think i'm able to use mysql_pconnect. my website is a php website that will access database for data searching, display, insert data(for user, that will allow multiple access ), and data manipulation(for admin which is not multiple access)...

 

so, if i'm using mysql_connect, is it enough for my purpose?

thanks!

Link to comment
Share on other sites

i have another question regarding connection, hope you guys can help...

 

if i'm using mysql_connect...

 

and my code check for the table update by using

 

if(mysql_affected_rows()>0)

 

if my table got only one row, and each update is for that row of record...

 

if at the same time, user A and user B doing the update to the table for the same row, same column...

and user A fail to update, but user B success to update...

 

so, my question is when user A fail to update, will

 

mysql_affected_rows()

 

return 1(from user B update) or 0(from user A update)?

Link to comment
Share on other sites

if my table got only one row, and each update is for that row of record...

 

If you have 1 row then the most that mysql_affected_rows() can be, is 1.  This doesn't have anything to do with users.  If you don't provide the function with a result_resource it will, by default, grab the last result resource that was executed.

 

 

Link to comment
Share on other sites

if my table got only one row, and each update is for that row of record...

 

If you have 1 row then the most that mysql_affected_rows() can be, is 1.  This doesn't have anything to do with users.  If you don't provide the function with a result_resource it will, by default, grab the last result resource that was executed.

 

i need to use mysql_affected_rows() to detect function/action performed by an user, so to carry out the following code for it...

if mysql_affected_rows() can return result from other user's action, then i can't control the which part of the following code need to execute...

 

how to solve it, please?

Link to comment
Share on other sites

You don't need a persistant mysql connection (pconnect) unless you've got an enormous web site running off a remote database.

 

sorry, english not my mother language...so, i'm not too sure about what you meant here...

 

is that you meant pconnect is only required when our website using remote database?

 

so, if my website and database reside in the same web hosting, then i have no problem to use normal mysql_connect?

Link to comment
Share on other sites

You don't need a persistant mysql connection (pconnect) unless you've got an enormous web site running off a remote database.

 

sorry, english not my mother language...so, i'm not too sure about what you meant here...

 

is that you meant pconnect is only required when our website using remote database?

 

so, if my website and database reside in the same web hosting, then i have no problem to use normal mysql_connect?

 

pconnect means persistent connection. Basically it means that you're always connected to the DB. The theory being, you limit the overhead of having to create the socket/connection for each request.

 

Considering the types you're having, I don't think you're a likely candidate for the benefits of the persistent connection.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.