Welcome Guest, Not a member yet? Register   Sign In
Extracting the ActiveRecord Library from CI
#21

[eluser]megabyte[/eluser]
So how would we write this for PHP4

Code:
Class ActiveRecordFactory {
    private static $dsn;
    private static $CIAR;
    public static function Factory($dsn=null)
    {
        if (!empty($dsn)) self::$dsn = $dsn;
        if (empty(self::$CIAR))
        {
            if (!empty(self::$dsn))
            self::$CIAR = new CI_DB_active_record($dsn) ;
            else
            throw new Exception("Please give a DSN in this format 'driver://username:password@hostname/database'");
        }
        return self::$CIAR;
    }
}
#22

[eluser]Nathan Pitman (Nine Four)[/eluser]
So far as I'm aware, you can't... you will need PHP5, that's what I found anyway...
#23

[eluser]megabyte[/eluser]
well, there has to be a way to do it? My php5 isnt that strong though. I've turned a few php5 to php4 before but when I tried with this it didnt seem to work.

Someone in this forum must have the skills. lol.
#24

[eluser]Nathan Pitman (Nine Four)[/eluser]
Possibly, when we were working on the project where we used Web Services it was simpler to just install PHP5 and get on with things. I too would be interested to see this work with PHP4 though. Smile
#25

[eluser]Maurice Calhoun[/eluser]
[quote author="megabyte" date="1213749982"]So how would we write this for PHP4
[/quote]


Convert php5 to php4


Code:
<?php // PHP4 clone & exceptions emulation (must be hidden behind PHP5 parser)
if (PHP_VERSION < 5) require_once('php4compat.php4');
?&gt;&lt;?php


$GLOBALS['ActiveRecordFactory::$dsn'] = NULL; /* class private static property */

$GLOBALS['ActiveRecordFactory::$CIAR'] = NULL; /* class private static property */
Class ActiveRecordFactory {
    function Factory($dsn=null) /* static */
    {
        if (!empty($dsn)) $GLOBALS['ActiveRecordFactory::$dsn']= $dsn;
        if (empty($GLOBALS['ActiveRecordFactory::$CIAR']))
        {
            if (!empty($GLOBALS['ActiveRecordFactory::$dsn']))
            $GLOBALS['ActiveRecordFactory::$CIAR']= new CI_DB_active_record($dsn) ;
            else
            throw (new Exception("Please give a DSN in this format 'driver://username:password@hostname/database'"));
        }
        return $GLOBALS['ActiveRecordFactory::$CIAR'];
    }

    function ActiveRecordFactory()  /* PHP 4 constructor */
    {
        // generate references (see http://latrine.dgx.cz/how-to-emulate-php5-object-model-in-php4)
        foreach ($this as $key => $foo) $GLOBALS['$$HIDDEN$$'][] = & $this->$key;

        // call php5 constructor
        if (method_exists($this, '__construct')) {
            $args = func_get_args();
            call_user_func_array(array(&$this, '__construct'), $args);
        }
    }
}

?&gt;
#26

[eluser]megabyte[/eluser]
Maurice, you got some skills!

I so need to get me some php5 books. lol

Tested and works.
#27

[eluser]Maurice Calhoun[/eluser]
I can't take any of the credit [url ="http://latrine.dgx.cz/how-to-emulate-php5-object-model-in-php4"]David Grudl[/url]
#28

[eluser]darkroomdave[/eluser]
I did a quick update of the Library I originally download from http://hasin.wordpress.com/2007/06/13/us...deigniter/

I updated it to use AR from 1.7.0

It works fine for me in a small project that I needed it for. But it has not been extensively tested.

http://www.documentopia.com/downloads/




Theme © iAndrew 2016 - Forum software by © MyBB