Forum Moderators: coopster
mysql_connect($host, $user, $pwd)
mysql_select_db($dbase)
I was thinking something involving sessions would work, but I am having trouble with it...
--Nick
First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mssql_close() will not close links established by mssql_pconnect()).
This type of links is therefore called 'persistent'.
A persistent connection is a connection that `remains alive`, but still requires the php function call to `pick up the connection`. On large traffic websites persistent connections can help reduce the amount of work the server has to do opening and closing connections, but it does take up extra resources (also be wary of using them if you are using transactions as open threads can remain until the connection is picked up again... big trouble if you have an uncommitted transaction).
A persistent connection will not mean that you don't have to call the database connection on each page.
If you want to save yourself the hassle of putting you database connection code at the top of each page then consider putting it in a seperate file and call it using the include() function:
<?php
include('dbconnect.php');
// Database enabled code here
?>