Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Database Connection Problem In Included File On Root Directory


I have a file called tophtml.php that connects to the database. It's in the root directory of the site. It works perfect in the root directory. But if I call it in a sub directory. (e.g. require("../tophtml.php") or require("C:websitesdogrealm ophtml.php")) I get errors saying it can't connect to the database.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting An Included PHP Script To To Include A File In The Same Directory.
I am a little stumped at why when I try to include a file in same
directory as the script being processed, it looks in the same directory
as the script that included it to begin with. Is there any way I can
get around this? Is there anyway to get the name and/or of the script
being processed, rather than the name and/or path of the script that
was first called?

Problem With A File Included Twice When I Want It To Be Included Once
I have a problem with a file that apparently is being included twice when I want it to be included once. I searched all my files and couldn’t find a place in which I am not calling it with include_once("file_name")

Is there a way to print or output in any way which file calls this file?
It could be an included file that calls this file, so I need to know the file name, not the page name that calls this file.

Included File Not Included Every Time
I have some pages where I'm including a header for the document - beginning of the HTML, style sheet, javascript, logos etc.

The problem is that sometimes it's being included and sometimes it isn't - and I'm talking even on the same page. The header file is in the same folder as the document I'm including it in, so I'm just using: PHP Code:

Warning: MySQL Connection Failed: Access Denied For User: 'root@localhost'
I am new in MySql & PHP3. I have downloaded php3 and extracted it. Not sure what to do with the config.inc.php3 file. I get the following error:

Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in lib.inc.php3 on line 255

Goto Root Directory
does anyone know how to goto the root dir on a LINUX server. I mean like go to parent directory of public_html. i want store a really secure file there and then use the iinclude function to get it when i need it. is this even possible. are there limitations for using the "../" command in include functions? i've obviously tried something like
include("../../../home/mydir/my_secure_script.php"); //doesnt work

Locating Root Directory
I posted earlier about finding a directory path from another directory. I tried to find the root directory of the site using the following variable:

$_SERVER['DOCUMENT_ROOT'];

Which I was then going to search to find the appropriate directory. However doc root is not defined on the server i'm using. So my question is this, is there another way to find the root directory and if not how can I set the document root variable? what do I need to change in the server configuration?

PHP Files Only Run In Root Directory?
I've installed a php forum script under a directory named 'forum', the script ran with no problems untill about a week ago, but now I get the following error: 'You don't have permission to access /forum/index.php on this server.'

Its has nothing to do with CMOD, I've tried that. Worst still it's not just the forum it's any PHP file thats under a directory. The thing is, I can run a PHP file from the root directory, but for some reason can't run the same file under another directory.

eg www.mywebsite/testfile.php --- will work fine www.mywebsite/newdirectory/testfile.php --- causes permission error

Could it be a .htaccess problem? Heres my error log report: Options ExecCGI is off in this directory: /home/mywebsite/public_html/forum/index.php P.S The forum script dosn't use CGI?

Site Root Directory?
I've posted this onto alt.php earlier and stumped all involved.
I didn't cross post for the usual reasons Anyone here got any ideas?
--------------------------------------

I am simply attempting to find my sites root directory so I can then step up
into a folder
in which I will have my INCLUDE code. This will allow me to easily refer to
my
INCLUDE code without messing about.

Now, This code...

It simply attempts to put a file into the root of my server space, and
recall it. It doesn't work.

The file write doesn't error and the file read fails without error.
Most importantly the file is nowhere to be seen!

<Added when sent to the domain provider>
--------------------------------------
I am worried the file is dropping into a space not allocated to my account
and that
this could cause you/I some problems if it were to overwrite an important
file.

Define Root Directory For Images
I want to have a root directory from which the images on different pages shall be displayed. I define it here:

define('image_root', '/web/d2/w/mydomain/mydomain.com/images/');
Then I try to pass this path to the image:
$imageurl = image_root . $myrow['image'];
echo "<div id=left><img src='$imageurl' border=1></div>";But it doesn't work...
Any ideas?

Display Image Above Root Directory
Is it possible to display an image that is above the root directory using php?

for example if i have an image in /home/user/uploads/test.jpg and lets say my root directory for my site is /home/user/public_html/

is it possible to display test.jpg on /home/user/public_html/index.html ?

i am trying to create a secure file upload script and i think not having the file be directly accessed by the public is one of the main steps.

.tmp Files Being Placed In The Root Directory By The 100's, Want It To Stop
Hi folks, I have a bit of a problem, perhaps one of you knows what is going on.

According to the sys admin at my ISP, something from my site (which is entirely php) is saving 100's of tiny files with the extension .tmp into the root directory on the server where my site is located.

He doesn't know very much about PHP and neither do I (this is the first site I've ever produced using it) so neither of us knows what could be causing it, there is one other site hosted on that server that is running PHP and it is doing the same thing, although the lion's share of temporary files are coming from my site.

I have a copy of the php.ini file that he emailed to me this morning, if it would help to post it please let me know and I will do so. We are not sure what is going on, but we would like to know if there is some way to make it stop (or at the very least, to get these files to destroy themselves once they're no longer usefull)

Also: I would like to thank SilkySmooth for his mail script, I used it awhile back and it got the job done. Thanks so much!

Problem With Locating Image Directory From Root
All i want to do is change my following method that works fine, so that it checks from the root directory.

This is what i originally have and works fine:

$file_name = 'products/'.$pId.'s.jpg'
if (file_exists($file_name))
$test = true;
else
$file_name = 'template/noimage.gif'

I tried changing the following line but it does not locate the image:
$file_name = '../products/'.$pId.'s.jpg'

The folder 'products' and 'template' are in the root directory.
ie. root/products...

Running Php Included From A Mysql Database
I'd like to include php-code out of a mysql (or odbc) database on a php-page and run that code.

Is that possible?

I know howto include normal text(&html) from a database to a php-page. But I'd like to work with templates, therefore in need just a little bit php-code in my database. (and included on my pages).

How Can I Find Out Parent (including) File Of Included File?
How can i find out parent (including) file of included file?
Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file  its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included?

I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me?

Is A PHP Variable Supposed To Be Seen In A .js File Included Into A .php File
Is a PHP variable supposed to be seen in a .js file included into a .php
file?

I have a client side javascript code stored in a .js file which is included
into a PHP file using
<script src="filename.js></script>

This code initialises a Javascript variable
var u="string";

The string is supposed to be the value of $HTTP_HOST

So, when initialise this variable like

var u=<? echo $HTTP_HOST;?>;

I sterted getting a javascript message Syntax Error

Am I doing something wrong, or PHP variables are not seen in included js
files?

Check If A File Has Been Included Before?
I want my scripts to be warning and error free. Is it possible to
check is a file has already been included as part of a "require",
"require_once" or "include" call in the script? I guess I could just
include everything and turn warnings/errors off, but I'd prefer not to
do that.

Retrieving Variables From Included File
I'm trying to use a variable created in a file I'm including from within a PHP script:

include("http://www.domain.com/script.php");
echo $variable; // $variable still empty?

The $variable is created inside script.php but is empty when I echo it from the calling script.

Is it the way I'm including the script via http? I have to do this since it's on another server.

Establishing PHP Session ID In An Included File
Forgive me if this doesn't make too much sense but I've been working on this
project all day and my brain is a bit fried.

To make some of my code more readable I made a file (called urls.inc) which
I include in my PHP scripts. This file contains functions to return a URL
with the session id tagged on the end. I've now found out that the session
id returned by the functions in urls.inc is not necessarily the current, and
more importantly correct, session id. I need to know if there is a way to
establish the current session id within the included file.

For info, I've built the scripts so that the session id is passed from page
to page to avoid using cookies (part of the challenge, it's a college
project) so I need the urls.inc file to know which session id to pass back
otherwise it all goes a bit squiffy.

Here's urls.inc :

<?php

session_start();

function logoutURL()
{
return "logout.php?PHPSESSID=" . session_id();
}

function adminURL()
{
return "admintools.php?PHPSESSID=" . session_id();
}

function homeURL()
{
return "main.php?PHPSESSID=" . session_id();
}

?>

These are called like this :
echo "<h3 align="center"><a href="" . adminURL() . ""
target="mainFrame">Administration Tools</a></h3>";

If it turns out that there's no way to do what I'm after then it's not big
deal because I can change the URL line to :
echo "<h3 align="center"><a href="admintools.php?PHPSESSID=" .
session_id() . "" target="mainFrame">Administration Tools</a></h3>";

Stopping Execution Of An Included File?
I have a structure like this: Code:

/index.php
/dir_1/index.php
/dir_2/index.php
.
.
/dir_n/index.php

In the topmost index.php file i have a switch statement selecting the current active directory (e.g. dir_2) and including the index.php file in that dir, if it exists. Is there any way I can stop the execution of the included file (/dir_2/index.php) without affecting the calling file (/index.php)?

Getting Cookie From HTTP_COOKIE_VARS In Included File
There's this thing about cookies that's bothered me and up until now I simply got around it. I can't do it anymore right now and I need to solve this problem, so I'm asking for some help.

I have used the include() function to include a few PHP bars and modules in a main PHP page. I can get cookies with the HTTP_COOKIE_VARS or $_COOKIE globals in the main page, but not in the included ones. If I open the included PHP pages as standalones, I can get the cookies.

I already had tons of problems with include(), I guess this is just another one. Can anyone tell me if it is supposed to be so (PHP manual says I can access the related global from anywhere) or if there's a way to fix this. The one thing I can't do is reading the cookies from the main page and passing them to the include, because that would mean changing code for the whole site.

BOF In The Included File Shows Up In The Browser
I have an UTF-8 PHP file which generates HTML
Then I cut the beginning of that file, pasted into another UTF-8 file ind
included this second file into the first one.
After that the whole page moved down about one libe leaving a gap at the top
of the browser window.

Viewing the resulting code of the first file via VIEW-Source, I and see a
square inserted before the included file.
This does not show if I open the included file with a Unicode supporting
text editor. A non-unicode editos shows i>?
at the beginning of the file which, I understand, is BOF.
So the problem is that the browser sees the second BOF and displays it as a
small square in a separate line

Included File Not Loading Completely
This is my first post to this list, so forgive me if this is very basic.

I have a file: overview.php that is including another file dolan_header.php

I have tested it on three servers...on two of them it works perfectly,
and on the third (the client's server) the header file fails to load the
first ~12 lines of code.

A functioning version of the page is here:
http://64.132.144.101/~somedom/dolan/overview.php

And a malfunctioning version is here:
http://dolanconcrete.com/staging/overview.php

I have placed the two PHP files here if anybody should care to inspect
them. http://64.132.144.101/~somedom/php/dolan_php_debug.zip

Require_once Fails If File Already Included
I am having a problem with multiple includes.

A.php require_once on two files: B.php then C.php

C.php require_once on B.php again

Then I get a message:

Warning: main(../../B.php): failed to open stream: No such file or
directory in
/home/jkennedy/public_html/foo/php/secure/common/A.php on line
1

Fatal error: main(): Failed opening required '../../B.php'
(include_path='/home/jkennedy/public_html/foo/php/secure:/usr/share/php:/usr/share/php/Smarty-2.6.2/libs:/home/jkennedy/public_html/foo/_php/secure/PEAR')
in /home/jkennedy/public_html/foo/php/secure/common/A.php on
line 1

If I comment out the second require_once of B.php in C.php, the error goes
away and I still get the variables defined in B.php, so I know it is being
included.

My question is why is it failing in the manner that it is doing? From
what I could tell in the manual require_once was supposed to do nothing if
it was already included. And why the "Failed opening", as if the file
didn't exist?

I am using PHP 4.3.4.

Read A File Below Root
How can I include a file from below the Root dir, other than using:
include "../../filename.inc.php";

Printing The Line Number And Name Of Included File
Does anyone know how to echo the line number and included file name in php.

I like to use development tags but sometimes I forget what included file they are in and what line they are on. I use a master variable to turn off all of the dev tags, but I would really like an easy way to automatically print the line number and file where the function is.

This would be like if there was an error, but with out breaking the script and with out generating a nasty error.

Requiring File From Root While In Sub-domain
I'm trying to include a file from my root directory but I can't figure out how to. The file that is requiring is in sub.domain.com and the file to be required is in domain.com.

How would I go about including it?

Database Connection ?
I am very new to PHP...Can i get the starting code for connecting to database....how to open the connection...what is the connectionstring ?

Database Connection
<?php

I have a question about 2 connection strings to a ms sql database.

# TEST DATABASE

$connecttest = MSSQL_CONNECT("TEST", "sa", "123456") or exit("Unable to
connect to MS SQL Server at 10.0.10.58");

$select = mssql_select_db ("database1",$connecttest) or exit("Unable to
select database TEST");

# PRODUCTION DATABASE

$connectprod = MSSQL_CONNECT("PROD", "sa", "654321") or exit("Unable to
connect to database at 10.0.10.59");

$select = mssql_select_db ("database2",$connectprod) or exit("Unable to
select database PROD");

$SQL = "SELECT * FROM table1";

$RESULT = mssql_query($SQL);

// What data will i find here? Is it data from the TEST or from PROD and
will it be data from database1 or from database 2?

?>

Connection To Database
Running RH8 and have installed mysql, apache, php. I have pypmyadmin working fine, adding and editing databases.. but when I try to get a form (to enter data) its does not connect or just sumbits as if all was ok but nothing happend.

Database Connection Limits?
I am in big confusion right now plz tell me one thing with explaination.

Situation is:

I have a script in that i am using database connection and some database operation. 10 users are accessing this script same time.

what happen is there 10 connection to database sever or there will be only one connection?? if there would be 10 connections then what is the max limit of mysql.


Class For Database Connection
Can anyone tell How to write class for database connection in PHP . Class must provide a general function for executing queries.

Closing A Database Connection
for my php site, i open a mysql connection for each page cause most of my pages uses some data from the database. however, i did not close the mysql connection - will this have any bad effect to my database? or is it better to have all connection closed once my php script is finished?

Database Connection Problems?
I am all new to php/mysql and was wondering if someone might help me
out on a little problem that I am having.
It must be something very simple that I am missing, it seems that I am
having trouble connecting to the database, yet all of my information
seems to be correct - the error is as follows:

Parse error: parse error in
/data/members/free/tripod/uk/t/h/e/theresearcher/htdocs/scripts/conf.inc.php
on line 6
the error repeats twice.

Line 6 in my conf.inc.php states:
$mysql_database='theresearcher_uk_db'

I have enabled both php and mysql twice just to be sure. Hostname
localhost is correct. Double checked the database name. No password is
required so i left it blank. (should I take the line out alltogether?)
I dont know what to do about the port..lycos didnt say anything about
it so I left it blank. The table prefix I am not sure of either.

Here is the surrounding code:
$mysql_hostname='localhost'
$mysql_port=''
$mysql_user='theresearcher'
$mysql_password=''
$mysql_database='theresearcher_uk_db'
$mysql_table_prefix=''
$mysql_pconnect="NO";
$pages_dir='/data/members/free/tripod/uk/t/h/e/theresearcher/htdocs/'
$pages_url='http://members.lycos.co.uk/theresearcher/pages/'
$scripts_dir='/data/members/free/tripod/uk/t/h/e/theresearcher/htdocs/;
$scripts_url='http://members.lycos.co.uk/theresearcher/scripts/'

Connection To Database Or Die Message
When connection to the database fails I would like to include an email link in the response message, but I need help with how it can be done.  Below is my code and I want the error message text to include a Report This email html link. Code:

Php Mysql Database Connection
i want to add my form details to the mysql database. i had done it with mysql_connect('localhost','root',''); but the error was localhost connection failed. Code:

PHP MySQL Database Connection
I'm involved in a project where I have to create a web application with PHP and MySQL. My question is, usually we use one user name and password to connect to the database for the whole application, in which case all the users will connect to the database with that username we set in PHP script.

If we want to have different users with various access rights on the database this strategy will not work, because we give one username and give maximum access rights for that username. Is there any way where you can define the access rights of a user in the database(MySQL) and use the same username and password when the user connects to database through PHP application?

If so, we will have hundreds of users connecting through the PHP application with different usernames and password, will this have any impact on the web server or DB server? Is it secure? Is there any other way this can be done?

Document Root Not Website Root
I want to use PHP in my website; but run into a snag, the recommended
method of calling an include is:
<?php include($_SERVER["DOCUMENT_ROOT"]."/inc/css-gateway.inc"); ?>

when I try
<?php ECHO $_SERVER["DOCUMENT_ROOT"]; ?> the document root is shown as
/usr/local/apache/htdocs/

However the website root is at:
/mnt/home/www/canadian-dream.com/www

How do I redirect $_SERVER["DOCUMENT_ROOT"] to the my website root? Is
there a global variable that can be used? I do not wish to rewrite a lot
of pages if I were to change web host in the future.

from the error logs

[Sat Oct 25 06:32:51 2003] [error] PHP Warning:
main(/usr/local/apache/htdocs/inc/css-gateway.inc): failed to open stream:
No such file or directory in
/mnt/home/www/canadian-dream.com/www/de/immobilien/main.php on line 15

[Sat Oct 25 06:32:51 2003] [error] PHP Warning: main(): Failed opening
'/usr/local/apache/htdocs/inc/css-gateway.inc' for inclusion
(include_path='.:/usr/local/lib/php') in
/mnt/home/www/canadian-dream.com/www/de/immobilien/main.php on line 15

PHP/MySQL Database Connection Problem
when I'm doing an insert (using mysql database) it produces the following two error messages :

Warning: MySQL: Unable to save result set in [file].

Lost connection to MySQL server during query

These errors occur after the number of conncections increases, before this there is'nt any problem.

I am using PHP 4 with Apache on Redhat Linux 6.2.

How To Make A Database Connection Available To All Pages?
How can I make a database connection available to all the pages in my
application? I tried doing it with session but it doesn't seem to work.

here's what a did:

What Is Going Wrong In The Database Connection With PHP MYSql
I am setting up a site for a client that requires signup and
login. I have written most fo the code but, for some reason am
have trouble with the database connection. The problem is with
the connection. I believe I have the right server but, have had
trouble getting the correct iser and password. Is there a way to
determine what is going wrong in the connection because
setting up die with a message doesn't tell me anything other
than the connection failed. I going back to client and getting the
support # from yahoo who set up the server and database.

Hopefully I can talk to the person who set up the server for him
and get the proper server, user and password. It would be nice
to know how to troubleshoot the connection in a more
meaningful way.

No Luck Making A Database Connection
I've included db.php into my script, and this is all it contains:

$host = 'localhost'
$username = '***'
$password = '***'
$database = '***'
$connection = mysql_pconnect($host, $username, $password);
$mysql_select_db($database, $connection);

obviously with the other fields filled out.

My webhost tells me to use this script:

$dbh=mysql_connect ("localhost", "<USERNAME HERE>", "<PASSWORD HERE>") or
die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("<TABLE NAME>");

neither one of these methods work, actually - I get this error:
[the contents of my db.php file here, in plain text!]No Database Selected

Database Class: Closing Connection
I am just learning OOP in PHP and I decided making a DB class would be a good start for my first real type of OOP class. Everything is working fine but I am having problem's closing the connection. I was wondering if anyone can see what the problem might be if it is in the coding. database.class.php PHP Code:

Hiding Database Connection Info
In a php script, I have to connect to a remote mysql database. I'm a bit
worried that some user might be bale to retrieve the source of the page and
see the user name and password to connect to the db.

Is this resonable? What's the best way to avoid it?

ADODB Multiple Database Connection
I'm using ADODB for a PHP project and am having problems with multiple (MySQL) databases. I've looked through all the docs and am stumped. I know how to use PHP and MySQL and I still haven't got a clue why this isn't working. Code:

How Do I Connect To A .mdb (access) Database With A Dsn-less Connection Using Php4?
I need to connect to an Access database without a dsn. Can you give me an example (a simple table display with a while !rs->eof)

Using Global Variables In The Database Connection String
I'm sure this has been asked a million times but I can't seem to
formulate a google search that returns what i'm looking for.

I've go a dev and live environment. Currently the DB connect string is
hard coded into each php file which means i'm going to have to change
every page - Arrgh!!

If i put the DBonnect into a function and store it in an include file,
it doesn't seem to work, Also the connetion works with inline PHP
statements, but I have to repeat it in every function even if they are
in the main php file??? which doesn't seem right to me..

I need to either :-

Store the connection variables in an include file and retrieve them as
global values

OR

Store the connection string in a function in an include file which can
be accessed by all functions.

also do I really have to call the dbconnect inside every function.

Please note, if it makes any difference, I still havn't got my head
round OO programming in PHP so it is still pretty much procedural. I
am using PEAR but dont really understand (or care at the moment) about
what it is doing.

Connect To Foxpro 2.6 DOS Database Using Php Odbc Connection.
The driver that I use in ODBC Data Source Administrator is Microsoft dBase Driver (*.dbf). Is it correct. Code:

Errors - Putty.exe (telent Connection To Mysql Database)
The following code produces an error when I try to run it under
putty.exe (telent connection to mysql database). Can anyone identify
the error in the code? The server is running PHP5.


DELIMITER ;;
/*!50003 DROP PROCEDURE IF EXISTS `aaa` */;;
/*!50003 SET SESSION
SQL_MODE="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER"*/;;
/*!50003 CREATE PROCEDURE `aaa`()
begin
declare iTest int;
set iTest = 5;
end */;;

Check If Database Exists Even If Connection Credentials Are Incorrect..
How can I check if database exists even if the connection credentials are incorrect?


Copyright © 2005-08 www.BigResource.com, All rights reserved