Page 1 of 1

need help with php include function

Posted: Fri Aug 22, 2008 1:21 am
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

Re: need help with php include function

Posted: Fri Aug 22, 2008 1:31 am
by archangeljess
I'm sorry if I posted on the wrong forum. How do I transfer this question to PHP code?

Re: need help with php include function

Posted: Fri Aug 22, 2008 9:11 pm
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.