note 19171 modified in function.mysql-connect by philip

From: Date: Fri, 24 May 2002 15:23:42 +0000
Subject: note 19171 modified in function.mysql-connect by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-30986@lists.php.net to get a copy of this message
Don't hesitate to connect and select your database in its own file and include it when needed. Like: include 'mysql_connect.php'; --was-- _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Connection Hint _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Do you always write at the code the username and password to connect to your MySql database !? If your username or password change ? What do you do ? - Change in all php files??? Are you Crazy ?!? Use this tip =) Create a connection.inc and include it in all php that you need to connect to MySql !!! If you have to change the username or password just change at the connection.inc file!!! _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Here is the Sample _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ --- connection.inc --- <?php $connection = mysql_connect ("localhost", "username", "PASSWORD") or die ("The DataBase is Down!"); mysql_select_db("databasename", $connection) or die ("I Can't connect at database!"); ?> // Use your username / PASSWORD / databasename // you can use $database name and pass it from the php file :) If you connect into different databases. --- Phpfile.php --- <?php include('connection.php'); // Include the connection to the databank THAN start your SQL Job :) $query_st = mysql_query("SELECT field FROM table WHERE filed = '$something' "); // Sample of SQL QUERY $fetch = mysql_fetch_row($query_st); // Sample of SQL QUERY mysql_close($connection); // Close this connection ?> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ I hope it could help you! []´s Helio Ferenhof d-m@eudoramail.com _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ http://www.php.net/manual/en/function.mysql-connect.php

« previous php.notes (#30986) next »