Dekieon Posted March 22, 2007 Share Posted March 22, 2007 I'm am fairly new to PHP, and it seems to be going good so far, but I have a question about accessing the SQL server. the way I have designed the site is by having the index.php being the page that is always getting rendered, and all other php files are called from the index.php. Many of the php files that get included need acsess to the SQL database. Would it be better to .... 1. open access to the SQL database at the beginning of the index.php file, and then close it again at the end of the index.php file. This would give all my php scripts access to the database without having to establish a connection to the database over and over again. or 2. Open access to the sql database only when i need information from it and then close it again right afterwards. This would cause me to open and close access to the database multiple times during page rendering. I am interested in page rendering speed, which option is faster? I am guessing that option 1 woud be faster. I am interested in security, which option keeps the SQL data more secure? I am guessing option 2 would be more secure. What is everyones opinion? Link to comment https://forums.phpfreaks.com/topic/43823-sql-database-access-question/ Share on other sites More sharing options...
trq Posted March 22, 2007 Share Posted March 22, 2007 Option 1 is your best bet. You, don't even need to close a database connection in php, it has great garbage collection that will do that for you and the end of each request. Link to comment https://forums.phpfreaks.com/topic/43823-sql-database-access-question/#findComment-212730 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 thrope is right. That will also shorten you scripts, and things will be easier to configure if you had to move a server or something. Also, you don't need to be worried about security. There's nothing more secure in option 2. Orio. Link to comment https://forums.phpfreaks.com/topic/43823-sql-database-access-question/#findComment-212741 Share on other sites More sharing options...
Dekieon Posted March 22, 2007 Author Share Posted March 22, 2007 Great that is the answer I was hoping for. Thank you for replying so quickly guys, it is much appreciated. Link to comment https://forums.phpfreaks.com/topic/43823-sql-database-access-question/#findComment-212743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.