« Winter urban exploration | Main | Mood »

PHP5RC1 ir cdb

Prieš kelias dienas gavau cdb (Compact database abstraction class) iš mentolio, bet išbandyti teko tik šiandien, ir kaip tik ant PHP5.
O gi meta klaidą!:)
"Cannot re-assign $this in ..."
codas :
...
$this = &new $class($config);
..
googliname ir randame Joe Lee komentarą

"The fact that you could change in PHP 4, was never really meant to be although it worked. In PHP 5 we removed this option due to performance and semantic reasons. In PHP 5, you can either use a factory method pattern or throw an exception on error in the constructor."
paklausiau #php ir iš Proton gavau "Gerą linką"

rezultatas: komentuoju visą cdb klasę ir, palikęs tik konstruktorių, parašau
...
function getInstanceFactory( $cfg )
{
isset($config['persistent']) || $config['persistent'] = false;
isset($config['username']) || $config['username'] = '';
isset($config['password']) || $config['password'] = '';
isset($config['database']) || $config['database'] = '';
isset($config['db_type']) || $config['db_type'] = CDB_MYSQL;
isset($config['host']) || $config['host'] = '';
isset($config['fetch_mode']) || $config['fetch_mode'] = CDB_FETCH_BOTH;
isset($config['seq_table']) || $config['seq_table'] = '_sequences';
isset($config['debug']) || $config['debug'] = false;
isset($config['err_func']) || $config['err_func'] = false;
isset($config['prefix']) || $config['prefix'] = '';

$class ='db'.$cfg['db_type'];
return new $class($cfg);
}
...
klasė sukuriame taip:
$db =cdb::getInstanceFactory( $configurations );

Jei kažkur klystu pataisykite:)

Comments

Cia SNK klasyte. vat tai jam ir pasiusk ja. beje, as kol kas ja naudoju ant php4, bet kazkada hostintojui pakeitus i php5, ji luz. tai jei netingi surask aukso viduri, kad taip nebutu