note 73983 added to function.mysql-connect

From: Date: Mon, 19 Mar 2007 21:07:34 +0000
Subject: note 73983 added to function.mysql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-124602@lists.php.net to get a copy of this message
The post from 'Graham_Rule at ed dot ac dot uk' should include the following WARNING: WARING: THE VALUES OF THESE DIRECTIVES WILL BE EXPOSED IF ANY OF THE CODE INCLUDES THE phpinfo() FUNCTION. The phpinfo() function will print these values clear as day. I highly suggest against this method of storing MySQL authentication information. I recommend creating connect and cleanup functions in a separate include file. If security is a concern, locate the include file outside of your web root folder. <?php $g_link = false; function GetMyConnection() { global $g_link; if( $g_link ) return $g_link; $g_link = mysql_connect( 'host.name', 'user', 'password') or die('Could not connect to server.' ); mysql_select_db('database_name', $g_link) or die('Could not select database.'); return $g_link; } function CleanUpDB() { global $g_link; if( $g_link != false ) mysql_close($g_link); $g_link = false; } ?> Simply include your connnection.php file in your script and anywhere you use the mysql_query() function include a call to the GetMyConnection() function. <?php $res = mysql_query("SELECT ...", GetMyConnection() ); ?> ---- Server IP: 216.194.113.175 Probable Submitter: 64.179.48.194 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php Edit -- https://master.php.net/note/edit/73983 Del: integrated -- https://master.php.net/note/delete/73983/integrated Del: useless -- https://master.php.net/note/delete/73983/useless Del: bad code -- https://master.php.net/note/delete/73983/bad+code Del: spam -- https://master.php.net/note/delete/73983/spam Del: non-english -- https://master.php.net/note/delete/73983/non-english Del: in docs -- https://master.php.net/note/delete/73983/in+docs Del: other reasons-- https://master.php.net/note/delete/73983 Reject -- https://master.php.net/note/reject/73983 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124602) next »