note 19171 added to function.mysql-connect
| From: | d-m at eudoramail dot com | Date: | Mon, 18 Feb 2002 18:14:55 +0000 |
| Subject: | note 19171 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26753@lists.php.net to get a copy of this message | ||
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
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
http://master.php.net/manage/user-notes.php?action=edit+19171
http://master.php.net/manage/user-notes.php?action=delete+19171
http://master.php.net/manage/user-notes.php?action=reject+19171