For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2004 > user and password in file and mysql_connect()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author user and password in file and mysql_connect()
Claus Ladekjær Wilson

2004-10-31, 3:56 pm

Here's my code:

<?php
$file_pointer_error='Der skete en fejl ved åbning af filen til
initialisering af koder<br>';
$mysql_connect_error='Beklager, der skete en fejl! - prøv igen en
anden gang!<br>(Webmaster må gerne vide, at det var en
<u>mysql_connect-fejl!</u> )';

$DOCUMENT_ROOT=$HTTP_SERVER_VARS['DOCUME
NT_ROOT'];
$fp=fopen("$DOCUMENT_ROOT/mysql/koder.php","r");
if(!$fp){echo $file_pointer_error; exit;}
$file_user=fgets($fp);
$file_passwd=fgets($fp);
fclose($fp);

$db_oplysninger =
array('db_name'=>'fuk_arrangement','host'=>'localhost','user'=>$file_user,'passwd'=>$file_passwd);

$db_conn = mysql_connect($db_oplysninger['host'], $db_oplysninger['user'],
$db_oplysninger['passwd']) or die( $mysql_connect_error);
?>

My file consists of user and password information.
I did echo $db_oplysninger['user'] and it shows the right letters.

What is wrong here?
J.O. Aho

2004-10-31, 3:56 pm

Claus Ladekjær Wilson wrote:
> Here's my code:
>
> <?php
> $file_pointer_error='Der skete en fejl ved åbning af filen til
> initialisering af koder<br>';
> $mysql_connect_error='Beklager, der skete en fejl! - prøv igen en
> anden gang!<br>(Webmaster må gerne vide, at det var en
> <u>mysql_connect-fejl!</u> )';
>
> $DOCUMENT_ROOT=$HTTP_SERVER_VARS['DOCUME
NT_ROOT'];


/* > $fp=fopen("$DOCUMENT_ROOT/mysql/koder.php","r");
> if(!$fp){echo $file_pointer_error; exit;}
> $file_user=fgets($fp);
> $file_passwd=fgets($fp);
> fclose($fp);


wouldn't it be easier to use */

include_once("$DOCUMENT_ROOT/mysql/koder.php");

/* Where the koder.php would look like:
<?PHP
$db_oplysninger = array('db_name'=>'fuk_arrangement',
'host'=>'localhost',
'user'=>'username',
'passwd'=>'thepasswordtouse');
?>
*/

> $db_conn = mysql_connect($db_oplysninger['host'], $db_oplysninger['user'],
> $db_oplysninger['passwd']) or die( $mysql_connect_error);
> ?>
>
> My file consists of user and password information.
> I did echo $db_oplysninger['user'] and it shows the right letters.
>
> What is wrong here?


As you don't provide with the error message, it's a bit difficult to say what
is wrong, do the following:

1. Check that the case and spelling of both username and password
2. Check that the connection is really made from localhost and not from the
hostname that the machine has (you could add that to the grant list).
3. Check that the mysql server is really running
4. Check that the needed mysql dll is loaded in the php.ini (or else you
don't have mysql support).


//Aho
Claus Ladekjær Wilson

2004-11-01, 3:56 pm

Thanks for your answer! A great help!

J.O. Aho wrote:

> Claus Ladekjær Wilson wrote:
>
> /* > $fp=fopen("$DOCUMENT_ROOT/mysql/koder.php","r");
>
> wouldn't it be easier to use */
>
> include_once("$DOCUMENT_ROOT/mysql/koder.php");
>
> /* Where the koder.php would look like:
> <?PHP
> $db_oplysninger = array('db_name'=>'fuk_arrangement',
> 'host'=>'localhost',
> 'user'=>'username',
> 'passwd'=>'thepasswordtouse');
> ?>
> */
>
>
> As you don't provide with the error message, it's a bit difficult to say
> what is wrong, do the following:
>
> 1. Check that the case and spelling of both username and password
> 2. Check that the connection is really made from localhost and not from
> the
> hostname that the machine has (you could add that to the grant list).
> 3. Check that the mysql server is really running
> 4. Check that the needed mysql dll is loaded in the php.ini (or else you
> don't have mysql support).
>
>
> //Aho


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com