SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 :
    PHP Code:
    ....
        function 
    RowCount$string )
        {
            
    $result $this->Query$string );
            return 
    mysql_num_rows$result );
            
    mysql_free_result$result );
        }
    ..... 
    I wanna call RowCount in this class :
    PHP Code:
    <?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 ) return TRUE;
        }
    }
    ?>
    index.php
    PHP Code:
    <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 ...

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    first of all; a class definition that calls global variables makes me leary... why is this not a singular ('Database') class?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 )

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by php_lover View Post
    But doesn't work ...
    Do you get an error?

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_lover View Post
    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 )
    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...
    Code:
            foreach ( $data as $index => $ket )
            {
                $mysql[] = $index;
                $value[] = $key;
            }
    Something doesnt line up here..

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 ...

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    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-...ms-768872.html

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got <pre> ...
    I attached 3 files ... last shot :]
    Attached Files Attached Files

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    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....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •