Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 27th, 2007, 02:32 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default setup database connection include file in PHP

Code:
<?php 
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'mypassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'crmpicco_mini';
mysql_select_db($dbname);
?>
Is there a way I can have all of this in a database include file at the top of all my scripts? When i try it it just errors. Can only some of it go in an include?

I tried:

Code:
<?php include("/mini/inc/db_conn.php"); ?>
It didn't like that, or splitting the code into two seperate files as one site had suggested. Incidentally, do I always need to use "<?php" can't I just have "<?" to open scripting tags?

Cheers in advance,
Picco

www.crmpicco.co.uk
www.ie7.com
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
Reply With Quote
  #2 (permalink)  
Old September 28th, 2007, 06:12 PM
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why didn't it like the include? Did it error out?

The code looks fine to have as its own include file. Try using require_once though instead of include....this will force php to use this file (if it can't find it through include....it simple continues execution of the program) if it cant find the file using require then you will get an error.

And in regards to using <?php as opposed to <?

This is a setting within php.ini use short open tags....if it is turned on you can use <?

* You should however just start using <?php because starting in version 6 and on this feature will no longer be available

http://mynameissteve.com
Reply With Quote
  #3 (permalink)  
Old September 30th, 2007, 04:18 PM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

ok cool, cheers for that. i'll give it a go again and postback up. I'll just keep using "<?php" and not get into the way of dropping the PHP.

Do you mean that as of PHP 6 the "short open tags" option will not exist? Does it not go down well with some?

Picco

www.crmpicco.co.uk
www.ie7.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to database using include file misskaos Classic ASP Basics 4 October 26th, 2006 10:50 AM
Connection string and file include trouble cramerjj Classic ASP Databases 2 February 26th, 2005 04:46 AM
Virtual Include PHP file in HTML aingalsbe PHP How-To 0 May 3rd, 2004 10:37 AM
while making setup how to include database(oracle) gaurav_chhabra_911 VB Databases Basics 0 April 28th, 2004 05:56 AM
include php inside the asp file karib Classic ASP Databases 2 November 25th, 2003 03:51 PM



All times are GMT -4. The time now is 04:50 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.