PHP Problem (9, permasaged)

1 Name: #!/usr/bin/anonymous : 2008-07-03 02:12 ID:AarZyAad

Here's my problem: My code is not including the file as I'd like it to. I have three files, test.php, main.php and config.php.

I required config.php in main.php and required main.php in test.php so I can test to see if logging in works for my system.

Basically:

config.php

define('DBHOST', 'localhost');

main.php

require('config.php');
... mysql connection stuff ...

test.php

require('main.php');

It however does not see the constants I defined in config.php and says

Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2005): Unknown MySQL server host 'DBHOST' (11001) in [filename] on line 15

As you can see it's defined in config.php. The thing that puzzles me is that it works if I go to main.php but not to test.php. Is there something I'm doing wrong? Any help would be very appreciated.

2 Name: #!/usr/bin/anonymous : 2008-07-03 04:10 ID:pvlLi3dI

better performance= using associative arrays;

config.php:

$config['username'] = 'faganon';
$config['password'] = '2hacker4u';
$config['hostname'] = 'db.gtfo.org';

so, main.php

(NEVER require. use require_once or include_once. unless you want to get redefining shit errors.)

include_once('config.php')
mysql_shit($config['hostname'], $blahblah);

if that fails, you can also try var_dump($config);

3 Name: #!/usr/bin/anonymous : 2008-07-03 04:37 ID:AarZyAad

Ok, fixed that problem. Thank you >>2. Now is there any way to make $config be global so I don't have to define it in my functions?

4 Name: #!/usr/bin/anonymous : 2008-07-03 04:41 ID:AarZyAad

>>3
scratch that. It was working on the page itself but not it's not working on test.php

:<

5 Name: #!/usr/bin/anonymous : 2008-07-03 05:13 ID:AarZyAad

I think the problem might be with my php.ini file. It apparently works with my debugger but not in my browser.

Also, here's the new error I'm getting

Warning: mysqli::mysqli() [function.mysqli-mysqli]: (28000/1045): Access denied for user 'ODBC'@'localhost' (using password: NO) in [filename] on line 15

I dumped $config like >>2 said to and it comes out NULL when I run it from test.php but when I run main.php I get the array of info about config. I've never fiddled with the config so I'm not sure what the problem might be.

7 Name: #!/usr/bin/anonymous : 2008-07-08 18:57 ID:o7Z2RVHZ

>>2

> better performance= using associative arrays;

That's the opposite of true.
It should be obvious that did is the case, but I just did some tests anyway, and found constants are three to six times faster than the same amount of data in associative arrays.

The problem OP seems to be having in the first post, though, is that he's using constants wrong.
When you define('SOMETHING', 'foo'), you use it as SOMETHING, not as 'SOMETHING' (which is just a string with the contents "SOMETHING").

8 Name: #!/usr/bin/anonymous : 2008-07-18 07:51 ID:Gpz6iOal

use a real language, not a bad designed toy. I could recommend you Perl+Mason :)

9 Name: #!/usr/bin/anonymous : 2008-08-09 08:18 ID:7P38Igiu

But PHP gets the job done and is easy to deploy and scale horizontally in share-nothing architectures.

This thread has been closed. You cannot post in this thread any longer.