orange08 Posted April 13, 2009 Share Posted April 13, 2009 i found there are two type of connection which are mysql_connect and mysql_pconnect... can i know for a normal php site, which connection is needed? Quote Link to comment Share on other sites More sharing options...
Boxerman Posted April 13, 2009 Share Posted April 13, 2009 mysql_connect will work just fine Quote Link to comment Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 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. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 13, 2009 Author Share Posted April 13, 2009 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! Quote Link to comment Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 so, if i'm using mysql_connect, is it enough for my purpose? thanks! It should be, Yes. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 13, 2009 Author Share Posted April 13, 2009 so, if i'm using mysql_connect, is it enough for my purpose? thanks! It should be, Yes. ok, thanks for the guidance! Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 15, 2009 Author Share Posted April 15, 2009 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)? Quote Link to comment Share on other sites More sharing options...
Maq Posted April 15, 2009 Share Posted April 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
mandred Posted April 15, 2009 Share Posted April 15, 2009 You don't need a persistant mysql connection (pconnect) unless you've got an enormous web site running off a remote database. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 16, 2009 Author Share Posted April 16, 2009 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? Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 16, 2009 Author Share Posted April 16, 2009 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? Quote Link to comment Share on other sites More sharing options...
keeB Posted April 16, 2009 Share Posted April 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.