FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 05-17-1999, 05:34 PM   Postid: 42570
stan
Site Owner
 
stan's Avatar

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Feb 1999
Location: Utrecht, NL
Posts: 101
mysql_pconnect() and .my.cnf

A question on the username / password when connecting to
MySQL from PHP. I now use:

Code Sample:

mysql_pconnect("localhost", $db, $pw);



I would, however, like to use

Code Sample:

mysql_pconnect("localhost"



where the username / password is read from one location like  the ~/.my.cnf file is used by the mysql command line tool.

This would make the PHP scripts easier to maintain (no changes when the password is changed), and it would make it less easier to find the username / password for the database.

Any suggestions?

Stan
stan is offline   Reply With Quote
Old 05-17-1999, 06:03 PM   Postid: 42571
Justin
Visitor
 
Justin's Avatar

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
The way I did it was I created a variables file that gets included whenever the database needs to be used. Inside of it is:


Code Sample:

<?
# Variables for database

# Host Name
$db_host = &quot;localhost&quot;;

# Database Name
$db_name = &quot;xhostfacts&quot;;

# User Name
$db_user = &quot;root&quot;;

# Password
$db_password = &quot;*****&quot;;

# table name
$db_table = &quot;web_host_packages&quot;;

#########################
# Connect to the database
$sqlnum = mysql_connect ($db_host, $db_user, $db_password);

if ($sqlnum < 1) {
     print &quot;<span class=main>Can't connect to $db_host</span>\n&quot;;
     print &quot;

\nMake sure all of your variables are correct.&quot;;
     exit;
} else {
     @mysql_select_db ($db_name);
}
?>




This has the variables in it and it performs the connection to the database making it easier. Then it's all in one place, making updates easier as well as eliminating the need to connect in every file - it's just done in the include file, so to perform a query I just say:


Code Sample:

include &quot;header.php3&quot;;
include &quot;vars.php3&quot;;
mysql_query(&quot;select * from $db_table where blah=blah&quot;
.
.
.




Let me know if this helps.

PS - username 'root' is only on my localhost hehe - not on the server

------------------
Justin Nelson
FutureQuest Support
Justin is offline   Reply With Quote
Old 05-17-1999, 06:54 PM   Postid: 42572
stan
Site Owner
 
stan's Avatar

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Feb 1999
Location: Utrecht, NL
Posts: 101
Thanks.

That certainly solves the maintainability aspect of my question.

Stan
stan is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 08:20 PM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.