Code Comments
Programming Forum and web based access to our favorite programming groups.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,'p
asswd'=>$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?
Post Follow-up to this messageClaus 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 wha
t
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
Post Follow-up to this messageThanks 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.