PHP Classes

Hi, I have a problem, how can i do ,i'm using PHP Version 5.

Recommend this page to a friend!

      Login Controller  >  All threads  >  Hi, I have a problem, how can i do...  >  (Un) Subscribe thread alerts  
Subject:Hi, I have a problem, how can i do...
Summary:Package rating comment
Messages:4
Author:kasmeesee
Date:2009-02-27 04:21:15
Update:2009-07-16 19:52:47
 

kasmeesee rated this package as follows:

Utility: Not sure
Consistency: Not sure
Documentation: Not sure
Examples: Not sure

  1. Hi, I have a problem, how can i do...   Reply   Report abuse  
Picture of kasmeesee kasmeesee - 2009-02-27 04:21:15
Hi, I have a problem, how can i do ,i'm using PHP Version 5.1.6 & mysql Client API version 5.0.24a and using xampp
this error wen i try=>Fatal error: Call to a member function real_escape_string() on a non-object in C:\xampp\xampp\htdocs\test-login\classes\database\database.inc


  2. Re: Hi, I have a problem, how can i do...   Reply   Report abuse  
Picture of Dave Hale Dave Hale - 2009-02-27 14:45:14 - In reply to message 1 from kasmeesee
Hi. The real_escape_string() on a none object means you might not have a link to your database.

the code is $new_string = $db->real_escape_string($string); in the database.inc file.

You need to make sure you're connected to the database you created.

I'll be honest and say the database class is basic at best though. find the log files and see if the error message from the function below is being logged.

Connection function in database.inc.
can simply change the $host, $user, $pass, $dbase valuse to match your MySQL connection.

function connect_to_database($by='') {

$this->flog('database access','database.txt');
if ($this->location == 'dev') {
$host = "localhost"; //Database host.
$user = "username"; //Database username.
$pass = "password"; //Database password.
$dbase = "your databasename"; //Database.
} else {
$host = ""; //Database host.
$user = ""; //Database username.
$pass = ""; //Database password.
$dbase = ""; //Database.
}
$db = new mysqli ( $host, $user, $pass, $dbase );

if (mysqli_connect_errno ()) {
$this->log ( 'error connecting to database' );
return false;
} else {
return $db;
}

}


You could also add a temp echo or two into the function above to check on screen while making sure its set up right.

eg.


$this->flog('database access','database.txt');
if ($this->location == 'dev') {
$host = "localhost"; //Database host.
$user = "username"; //Database username.
$pass = "password"; //Database password.
$dbase = "your databasename"; //Database.
} else {
$host = ""; //Database host.
$user = ""; //Database username.
$pass = ""; //Database password.
$dbase = ""; //Database.
}
$db = new mysqli ( $host, $user, $pass, $dbase );

if (mysqli_connect_errno ()) {
$this->log ( 'error connecting to database' );
echo '**** No database connection ****';
return false;
} else {
echo '**** Connection to database - remove these echos ****';
return $db;
}

}

  3. Re: Hi, I have a problem, how can i do...   Reply   Report abuse  
Picture of Dave Hale Dave Hale - 2009-03-07 11:21:06 - In reply to message 2 from Dave Hale
Hi, did you manage to get the class connecting to MySQL or you decide to pass on it?

I've just found out i had left in extra code that was throwing an error message about not adding new members to the database when it was. (i was adding user priv's to a none related table)

This wont fix the problem you had/have with MySQL connection though, you need to check username / password and host (server) details with your web host or cPanel,if you have it, for that.

  4. Re: Hi, I have a problem, how can i do...   Reply   Report abuse  
Picture of petar petar - 2009-07-16 19:52:47 - In reply to message 3 from Dave Hale
hi i have the same problem as the guy that posted earlier, it doesnt want to connect to the database, but i dont know why.
if i run a simple one like - >

$mysqli = new mysqli("localhost", "root", "", "up");

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
printf("Host information: %s\n", mysqli_get_host_info($mysqli));
}

It doesnt throw any errors

the class in database.inc throws
Warning: mysqli::mysqli() [function.mysqli-mysqli]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\login\classes\database\database.inc on line 23

with the same setttings, any ideas?
thanks alot