Registering Zend Database Adapter in Registry

后端 未结 9 2028
温柔的废话
温柔的废话 2020-12-23 00:07

I am looking to register a reference to the main Database Adapter in the Registry during Bootstrapping so it can be used elsewhere in my site (specifically the Authorisation

9条回答
  •  囚心锁ツ
    2020-12-23 00:18

    Check the zend-documentation at : 15.5.3.3. Storing a Database Adapter in the Registry

    http://framework.zend.com/manual/en/zend.db.table.html

    $db = Zend_Db::factory('PDO_MYSQL', $options);
    Zend_Registry::set('my_db', $db);
    
    // Later...
    
    $table = new Bugs(array('db' => 'my_db'));
    

    something like that you're looking for?

    Edit:
    to load your configuration from an ini-file, use:
    parse_ini_file($inifile)

    ;configuration.ini
    host = 127.0.0.1
    user = username
    password = blabla
    
    ;yourfile.php
    $options = parse_ini_file('configuration.ini');
    
    $db = Zend_Db::factory('PDO_MYSQL', $options);
    

提交回复
热议问题