Call function from a class in another class

Hi guys I think this is repetitive and most asked question … how Can I call a function in a class in another class ?
mysql class :


....
    function RowCount( $string )
    {
        $result = $this->Query( $string );
        return mysql_num_rows( $result );
        mysql_free_result( $result );
    }
.....

I wanna call RowCount in this class :


<?php
class Authentication
{
    function Login( $table = NULL , $data = array() )
    {
        if ( ( $table !== NULL ) or ( !is_array( $data ) ) ) return FALSE;
        foreach ( $data as $index => $ket )
        {
            $mysql[] = $index;
            $value[] = $key;
        }
        global $db;
        $row_count = $db->RowCount("Select * from ".$table." where ".$mysql[0]." = '".$value[0]."' and ".$mysql[1]." = '".md5( $value[1] )."'");
        if ( $row_count > 0 ) return TRUE;
    }
}
?>

index.php

<pre>
<?php

$config['hostname'] = 'localhost';
$config['username'] = 'root';
$config['password'] = '';
$config['database'] = 'auth';


require_once('mysql.class.php');
require_once('auth.class.php');

$data = array ( 'username' => 'admin' , 'password' => '21232f297a57a5a743894a0e4a801fc3' );

$db = new MySQL();
$db->SetUpParam( $config );

$connection = new Authentication();
if ( ( $connection->Login ( 'admin' , $data ) ) === TRUE ) echo 'Admin!';


But doesn’t work … :slight_smile:

first of all; a class definition that calls global variables makes me leary… why is this not a singular (‘Database’) class?

it’s singular class , I paste the peace of code of that class , can anybody tell me how can I call a function in a class in another class ? ( with source example )

Do you get an error?

Well no, it’s not a single class, or you wouldnt be asking the question, because the methods would all belong to a single class.

Now, as to your problem…


        foreach ( $data as $index => [COLOR="Red"]$ket[/COLOR] )
        {
            $mysql[] = $index;
            $value[] = [COLOR="Red"]$key[/COLOR];
        }

Something doesnt line up here…

I fixed it but doesn’t work … is that my way correct ?
no I didn’t get anything … just blank page appears …
t never went through RowCount() function …

just a blank page. Does the <pre> tag show up? If not, you’ve got a WPSE, and should read http://www.sitepoint.com/forums/php-34/common-php-problems-768872.html

I got <pre> …
I attached 3 files … last shot :]

I’ll take a look when the files get approved…

Something i did notice is that you’re sending the admin password in what looks like already MD5’d format, and then md5’ing it again in your authentication class…