Guest_imported
New member
- Jan 1, 1970
- 0
Ok, I'm still new to this, so I'm looking for constructive help here. ;-) I'm having some problems getting my connection information to work from an .inc file that is called up by a .php3 file. For example, initially, I had hardcoded the connection information, setting the start.php3 file like this:
<?
$db_name = "my_db";
$table_name = "products";
$connection = @mysql_connect("localhost", "bob", "x8di32" or die("Sorry, can't connect"
$db = @mysql_select_db($db_name, $connection) or die("sorry, couldn't select database"
$sql = "
SELECT prod_id, distributor, cost, year
FROM $table_name
WHERE year > '$lowyear'
ORDER BY year
";
$result = @mysql_query($sql, $connection) or die("sorry, couldn't execute query."
...
This worked just fine. HOWEVER, I'm concerned about having the database, username, and password hardcoded in this file... (Should I be concerned about this if the file can't be viewed through 'source' in the browser or saved?)
SO THEN... I tried to put the password/login info in one file (stuff.inc) and the rest in the main file (start.php3)... doing something like this:
======================start.php3
<?php
require('stuff.inc');
?>
<?
$table_name = "products";
$db = @mysql_select_db($db_name, $connection) or die("sorry, couldn't select database"
$sql = "
SELECT prod_id, distributor, cost, year
FROM $table_name
WHERE year > '$lowyear'
ORDER BY year
";
$result = @mysql_query($sql, $connection) or die("sorry, couldn't execute query."
...
======================stuff.inc
<?php
$dbname = 'my_db;
$hostname = 'localhost';
$username = 'bob';
$password = 'x8di32';
$connection = @mysql_connect($hostname, $username, $password) or die("Sorry, can't connect"
?>
THE PROBLEM IS... When I run this, I get the 'sorry, couldn't execute query' message.
Any suggestions?
Thanks!
<?
$db_name = "my_db";
$table_name = "products";
$connection = @mysql_connect("localhost", "bob", "x8di32" or die("Sorry, can't connect"
$db = @mysql_select_db($db_name, $connection) or die("sorry, couldn't select database"
$sql = "
SELECT prod_id, distributor, cost, year
FROM $table_name
WHERE year > '$lowyear'
ORDER BY year
";
$result = @mysql_query($sql, $connection) or die("sorry, couldn't execute query."
...
This worked just fine. HOWEVER, I'm concerned about having the database, username, and password hardcoded in this file... (Should I be concerned about this if the file can't be viewed through 'source' in the browser or saved?)
SO THEN... I tried to put the password/login info in one file (stuff.inc) and the rest in the main file (start.php3)... doing something like this:
======================start.php3
<?php
require('stuff.inc');
?>
<?
$table_name = "products";
$db = @mysql_select_db($db_name, $connection) or die("sorry, couldn't select database"
$sql = "
SELECT prod_id, distributor, cost, year
FROM $table_name
WHERE year > '$lowyear'
ORDER BY year
";
$result = @mysql_query($sql, $connection) or die("sorry, couldn't execute query."
...
======================stuff.inc
<?php
$dbname = 'my_db;
$hostname = 'localhost';
$username = 'bob';
$password = 'x8di32';
$connection = @mysql_connect($hostname, $username, $password) or die("Sorry, can't connect"
?>
THE PROBLEM IS... When I run this, I get the 'sorry, couldn't execute query' message.
Any suggestions?
Thanks!