472,805 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Defining variables in a seperate file

I am missing a trick here on how use variables defined in seperate file.

In script 1, I have proved to myself my class is working OK because I can
pass in the values and the echo statement outputs the value of localhost.

<?php
// Script 1
// This script works and outputs the name of localhost
require_once("class.MySQL.php");
$db = new MySQL("localhost", "user", "password", "database");
echo "Name of host: ".$db->host;
?>

However if I assign these values in a seperate file called configuration.php
and put the $variable names in the instantiation statement, it doesn't seem
to work. Can't understand why it doesn't work because I reckon it should
still be passing in the values of $localhost, $user, $password and $database
which is exactly as script 1.

<?php
/* Script 2
This script does not seem assign a value to $localhost
Here is the contents of config.php without the open/close PHP tags.
$host = "localhost";
$user = "user";
$password = "password";
$database = "database"; */

require_once("configuration.php");
require_once("class.MySQL.php");
$db = new MySQL($localhost, $user, $password, $database);
echo "Name of host: ".$db->host;
?>

Appreciate any comments. I am sure I have overlooked something very obvious.

Cheers

Phil

May 23 '06 #1
6 1630
Rik
One of two?
$host = "localhost";
$db = new MySQL($localhost..... Here is the contents of config.php
require_once("configuration.php");


Grtz,
--
Rik Wasmus
May 23 '06 #2
Rik
Rik wrote:
One of two?
$host = "localhost";
$db = new MySQL($localhost.....

Here is the contents of config.php
require_once("configuration.php");


BTW: this is one of the reasons I like to build code with E_NOTICE on: if
would have given me notive $localhost is undefined...

Grtz,
--
Rik Wasmus
May 23 '06 #3
ph********@f-in-stupid.co.uk says...
<?php
/* Script 2
This script does not seem assign a value to $localhost
Here is the contents of config.php without the open/close PHP tags.
$host = "localhost";


Maybe because you've called it $host not $localhost ??

GM
May 23 '06 #4

"Geoff Muldoon" <ge***********@trap.gmail.com> wrote in message
news:MP************************@news.readfreenews. net...
ph********@f-in-stupid.co.uk says...
<?php
/* Script 2
This script does not seem assign a value to $localhost
Here is the contents of config.php without the open/close PHP tags.
$host = "localhost";


Maybe because you've called it $host not $localhost ??

GM


Yes, typical I've been looking at this for 2 hours and 5 mins after posting
I spot my obvious mistake.

Thanks for taking the trouble.

Cheers

Phil
May 23 '06 #5
On 2006-05-23, Phil Latio <ph********@f-in-stupid.co.uk> wrote:

"Geoff Muldoon" <ge***********@trap.gmail.com> wrote in message
news:MP************************@news.readfreenews. net...
ph********@f-in-stupid.co.uk says...
> <?php
> /* Script 2
> This script does not seem assign a value to $localhost
> Here is the contents of config.php without the open/close PHP tags.
> $host = "localhost";


Maybe because you've called it $host not $localhost ??

GM


Yes, typical I've been looking at this for 2 hours and 5 mins after posting
I spot my obvious mistake.


Just add the following lines to your scripts (or change your php.ini)
while you're developping: (It really does make you write less mistakes)

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
May 23 '06 #6
> Just add the following lines to your scripts (or change your php.ini)
while you're developping: (It really does make you write less mistakes)

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>


Thanks. That is a great tip, I just tried it on the file which I was
originally having problems with and the error message was very useful.

Cheers

Phil
May 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Mark Parnell | last post by:
I'm relatively new to PHP, and have just converted a site from ASP to PHP. There is one thing I haven't managed to do, though. When the site was using ASP, I had one file (called variables.asp),...
13
by: Larry L | last post by:
I have a Module that declares several arrays as public, some string, some integers. I then have 2 forms. Form A is the main form, that loads on start-up, and has a command button to open Form B. On...
5
by: Tony Archer | last post by:
Ok, first I know there are some db ways around this BUT I'll ask it anyhow: I have a couple ASP applications running on my server (non .NET) I would like to be able to get a sum total of how...
3
by: Microsoft | last post by:
I am using Session variables in my ASP application. I have tested the application on a Win2k professional and it works fine. When the same web app is installed on a win2k advanced server from the...
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
42
by: Dooglo | last post by:
I'm new VB and programming all together, but I'm getting he hang of it. My question is; I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch (...
13
by: Ørjan Langbakk | last post by:
I wanna make a file that holds the complete pricelist for a small webshop (yes, I know that a database in the background would be a lot simpler, but that is not an option today, unfortunately). ...
4
by: Hans | last post by:
Hi, I want to define a couple of constant strings, like in C: #define mystring "This is my string" or using a const char construction. Is this really not possible in Python? Hans
7
by: Roman Mashak | last post by:
Hello, I have a small piece of code, compiled by two 'gcc' and 'borland builder compiler'. The latter one produces warnings: Public symbol '_freq' defined in both module...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.