Jump to content

Includes


vchris

Recommended Posts

Hi all!I'm working on my new portfolio. I formatted my comp about 2 months back and reinstalled php, mysql, IIS 5.1... Everything works great. I can view php pages but I have 2 issues:1. Seems like I can't use absolute paths. Before formatting my comp I could modify the root folder in IIS to the site I was developing and absolute paths worked. Now when I do that, it only works for html/css and not for php includes. This works in html: <a href="/gallery/index.php">...</a> but this <?php include('/includes/header.php'); doesn't. File location is correct.2. I then tried to do a select from the db. I have 1 table with 1 row for now. I have a php file named mysql_connect.php which contains this code:

<?php//This file contains the database access information.//This file also establishes a connection to MySQL and selects the database.//Set the database access information as constants.DEFINE ('DB_USER', 'root');DEFINE ('DB_PASSWORD', '******');DEFINE ('DB_HOST', 'localhost');DEFINE ('DB_NAME', 'dc');//Make the connection$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );//Select the database@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );?>

This is the exact same code that I used to work before to connect to DBs so I don't understand why this wouldn't work. The output on the page simply stops right before this include as per the source code.BTW DB pass is correct.If you need more info, just ask!

Link to comment
Share on other sites

you know, that used to happen on one of my webhosts... I don't know why. is this on your local machine? if so, try it on a remote host if you can.
Yes this is on my dev server (my machine). Unfortunately I don't have access to another web server I could test this on. So no solution?
Link to comment
Share on other sites

Put echo statements around to figure out where the control flow is going. It's much easier to debug a problem if you at least know where the execution path is. Try changing include to require and see if it generates an error.

Link to comment
Share on other sites

Put echo statements around to figure out where the control flow is going. It's much easier to debug a problem if you at least know where the execution path is. Try changing include to require and see if it generates an error.
I tried that. I put an echo statement right after where I included the mysql_connect.php file and nothing displayed. If I check the source code it stops right before the include. I can still include other files like header.php. I guess it has to do with the connection info but it is correct. I tested the login on another program (navicat 2004) and it connects and I can perform queries no problem.oh yeah and I always use require_once('mysql_connect.php'); for that file. Always worked.
Link to comment
Share on other sites

Try using an echo statement right before the require statement, another one inside the file itself, and a third after the statement. All three of them should print.
I just tried that and it seems like it stops echoing after this line:
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

But why wouldn't it give me at least an error message?

Link to comment
Share on other sites

The @ sign keeps it from showing an error :) This OR in between, defines an alternate if there is an error in the first method. But if the error gets ignored, the alternates get ignored too. So use either the @ sign to just ignore all errors in the method you use, or the OR with its alternates :)So here it would get:

$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );
or
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
Edited by Dan The Prof
Link to comment
Share on other sites

Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\deepcoding\includes\mysql_connect.php on line 10Line 10:

$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

Link to comment
Share on other sites

in the php.ini, there will be a line like this:;extension=php_mysql.dllyou need to remove the semicolon (; ) and make sure that the file php_mysql.dll is in the php folder. the default location of the dll if it isn't in the php folder is the php/ext folder. copy it from there. of course, this is with Windows. I don't know how in linux.

Link to comment
Share on other sites

That's great but what if I don't have the file php_mysql.dll in my PHP folder??? Would it be some similar solution to resolve my absolute path problem with php?

Link to comment
Share on other sites

There is a configuration setting in php.ini that specifies the extension directory, so look there and make sure that it is pointing to the correct directory in the first place. If you can't find where it is, search for php*.dll on your computer. If you don't find the mysql extension at all, you probably installed PHP5 with the Windows installer, which does not include MySQL support. You will need to use the manual installation package, which includes all of the extensions.

Link to comment
Share on other sites

I already told you. it's in the subfolder /ext in the php directory. copy it from there.
No subfolder ext in php folder
There is a configuration setting in php.ini that specifies the extension directory, so look there and make sure that it is pointing to the correct directory in the first place. If you can't find where it is, search for php*.dll on your computer. If you don't find the mysql extension at all, you probably installed PHP5 with the Windows installer, which does not include MySQL support. You will need to use the manual installation package, which includes all of the extensions.
Where can I get this manual installation package?
Link to comment
Share on other sites

Those packages are the installation packages for PHP. You won't want to use the Windows installer, where you have a wizard that walks you through everything. Just download the zip file, extract all the files, copy them to their own folder, and go through the installation guide. It will tell you what files you need to put where, and how to hook it up with your server.

Link to comment
Share on other sites

OK so I uninstalled my PHP version and installed the PHP 5.1.4 manually but when I view php pages I get a pop up to download the file...

Link to comment
Share on other sites

So it is resolved!I was installing PHP 5 manually but followed all the steps and still didn't work. I installed PHP 5 with the windows installer and added the mysql extension and everything works.:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...