need help with php include function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
archangeljess
Forum Newbie
Posts: 3
Joined: Fri Aug 22, 2008 12:56 am

need help with php include function

Post by archangeljess »

I am trying to connect to a mysql database with my php code but I can't make it work if i separate my connection parameter in an include file. However, if I embed my connection parameters in the same page that needs connection to mysql, everything works fine. Here is my php code:

connection.inc.php

Code: Select all

 
<? php
    $username = 'test';
    $password = 'test';
    $hostname = 'localhost';    
    $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
?>
 
login.php

Code: Select all

 
...
<?php
    include "connection.inc.php";
?>
...
 
$result = mysql_query("select * from system.user where username = '$user and password = '$pass' " ) or die(mysql_error());
 
I am getting this error:
Access denied for user 'ODBC'@'localhost' (using password: NO)

Thanks for the help.

Jess
archangeljess
Forum Newbie
Posts: 3
Joined: Fri Aug 22, 2008 12:56 am

Re: need help with php include function

Post by archangeljess »

I'm sorry if I posted on the wrong forum. How do I transfer this question to PHP code?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: need help with php include function

Post by califdon »

I would try putting the connection inline with the rest of the code to see if it then allows you to connect. I would guess that it has nothing to do with your use of the include statement.
Post Reply