Jump to content

functions with PDO


prince198

Recommended Posts

hi

i have little problem to put function in PDO CLASS

there is class pdo

 



$database_type = 'mysql';

class mysql extends PDO {
    function column_data() {
        print 'Mffffysql Column Data';
    }
}



class db {

    // Declare instance
    private static $instance = NULL;

    /**
    * Return DB instance or create intitial connection
    */
    public static function instance() {
        //Get the type of database we are using
        global $database_type;
        
        if (!self::$instance) {
            self::$instance = new $database_type("mysql:host=localhost;dbname=cm", 'root', '');
        }
        return self::$instance;
    }


}

 

and i had to add this function in db class .



$db = db::instance();

function calcul($sar,$type)

  {

$statment = $db->query('select sum(Total) as som , week(date,1) as week from hours where brig like'%$sar%' and proc like '%$type%' group by week(date,1)'); 
$result = $statment->fetch(PDO::FETCH_ASSOC);
echo '<table>';
foreach ($result as $row)

                   {
			  $som = $row['som'] ;

                   }
echo '</table>';
			  
}				   

and after i called this function

 

calcul('AM','PH');

 

but i have this errors

 

Notice: Undefined variable: db in C:\Program Files\EasyPHP 2.0b1\www\PIC PARIS NORD\RH\class_rh.cls.php on line 51

 

???  althoug i put $db = db::instance();

Link to comment
https://forums.phpfreaks.com/topic/118293-functions-with-pdo/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.