Web Hosting Talk







View Full Version : [php] Help!


JustinSmall
06-18-2006, 06:21 PM
I need help, I'm creating a relatively small billing system for my site...

I believe I'm connected to mysql, I'm not sure, because when I go to display the info of the mysql table, it doesnt do it.

Here we go.

Heres the "classes/mysql.php" which holds all the sql info in it.


<?php
class MySQL
{
function connect($host, $username, $password, $database)
{
mysql_connect($host, $username, $password);
mysql_select_db($database);
}

function safe_query($query)
{
return mysql_query( mysql_real_escape_string($query) );
}

function get_config()
{
$res = $this->safe_query("SELECT * FROM config");
while( $row[] = mysql_fetch_assoc($res) ){}
return $row;
}

}
?>


Heres the index.php file


<?php
include ("includes/connect.php");
include ("classes/mysql.php");
$openconnect = new MySQL();
$openconnect->connect($host, $username, $password, $database);
$openconnect->get_config();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $row["sitename"]; ?></title>
</head>

<body>
<?php
print_r($row);
?>
</body>
</html>


Plus I have the includes/connect.php file which just holds the sql connection info such as user and the database and whatnot, not really needed to be shown here.

Well when I go to display the info, it doesn't do anything. It's just blank.

Thanks in advance!

Oras
06-18-2006, 08:55 PM
mysql_connect($host, $username, $password) or die("Cannot Connect to DB"); <---- add a die to check

also did you give the permission for that user to that DB?

sngskunk
06-18-2006, 10:10 PM
IF that told you that you werent connect you could try editing you mysql connect function to this:


function connect($host, $username, $password, $database)
{
$clink = mysql_connect($host, $username, $password);
mysql_select_db($database, $clink);
}

JustinSmall
06-18-2006, 11:05 PM
It doesn't give me an error when I put in


mysql_connect($host, $username, $password) or die("Cannot Connect to DB");


Yes I did, full permission.


I changed the database on my includes/connect.php to the wrong one to see if it would print me out an error, this is my error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hostinga/public_html/nb/classes/mysql.php on line 18

then I changed the assoc to array and it print out the same error but with array instead of assoc.

So then I removed all of the excess coding and I still don't get any errors about a wrong database...

maxymizer
06-19-2006, 02:12 AM
Use mysql_error() to find out what's wrong with your query. When PHP reports a warning such as "supplied argument is not a valid MySQL result resource" - it means that some kind of sql syntax error occured.