Hey, i have been programming php for a month now, well learning. And a friend asked me if i have done classes, as in class function etc and i said no. So he said its easy and that.
Spent awhile looking for help but no where actually gives you the info i need.
Anywayi have a class file called class.inc.php. And because i am using mysql i want a DB class.
Here is my code
[PHP]
<?
class db
{
var $db;
var $con;
function getdb()
{
$db['dbhost'] = 'localhost';
$db['dbusername'] = 'root';
$db['dbpassword'] = '';
$db['dbname'] = 'logg';
return $db;
}
function connect()
{
$host = $db['dbhost'];
$db = $db['dbname'];
$user = $db['dbusername'];
$pass = $db['dbpassword'];
mysql_connect($host, $user, $pass);
mysql_select_db($db);
return $con;
}
$db = new db();
?>[/PHP]
So my next file index.php basically shorten down to look like this
[PHP]
require('class.inc.php');
$db->con;
$result = mysql_query("SELECT * FROM news");
while($row = mysql_fetch_array($result))
{
echo $row['id'];
echo "<br />";
}
[/PHP]
And nothing appears, and i have 7 records and not even 1 shows.
This is the error that appears
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\ini\htdocs\ryan\2\index.php on line 46
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\ini\htdocs\ryan\2\index.php on line 46
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\ini\htdocs\ryan\2\index.php on line 48
Any help would be appreaciated alot! Thanks