문제

How do I check if the initialisation was successful after I do this?

ActiveRecord\Config::initialize(function($cfg){
    $cfg->set_model_directory('models');
    $cfg->set_connections(array(
        'development' => "mysql://root:root@localhost/blog"
        ));  
});

And then I go onto doing something like:

$posts = Post::all();

Just before performing the above I'd like to check if the initialization was successful.

With a PDO object I could do:

if $con ? /*execute query*/ : /*failed to connect*/

How could I achieve the same assurance with ActiveRecord?

도움이 되었습니까?

해결책

You can either check the connection from some instance you have (lets say you have got some model instantiated as $model), like so:

$model->connection();

You can probably do it statically, by calling the connection class

\Activerecord\Connection::instance();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top