symfony2读取数据库配置文件的信息

var_dump($this->getDoctrine()->getConnection()->getParams());
array(8) {
  ["driver"]=>
  string(9) "pdo_mysql"
  ["host"]=>
  string(9) "127.0.0.1"
  ["port"]=>
  string(4) "3306"
  ["user"]=>
  string(4) "root"
  ["password"]=>
  string(3) "123"
  ["charset"]=>
  string(4) "UTF8"
  ["dbname"]=>
  string(7) "www.xuejiehome.com"
  ["driverOptions"]=>
  array(0) {
  }
}


这些参数我们也是可以单个读取的,我们可以先看下这个类中都有哪些方法:

var_dump(get_class_methods($this->getDoctrine()->getConnection()));
array(59) {
  [0]=>
  string(11) "__construct"
  [1]=>
  string(9) "getParams"
  [2]=>
  string(11) "getDatabase"
  [3]=>
  string(7) "getHost"
  [4]=>
  string(7) "getPort"
  [5]=>
  string(11) "getUsername"
  [6]=>
  string(11) "getPassword"
  [7]=>
  string(9) "getDriver"
  [8]=>
  string(16) "getConfiguration"
  ......
}

可以看出我们也是可以单独获取到host、database、port等信息的。

$this->getDoctrine()->getConnection()->getDatabase();
$this->getDoctrine()->getConnection()->getHost();
$this->getDoctrine()->getConnection()->getPort();


by 雪洁 2015-04-10 06:15:45 2159 views
我来说几句

相关文章