连接数据库

一、全局配置定义

  1. return array(
  2. 'DB_TYPE' => 'mysql',
  3. 'DB_HOST' => '127.0.0.1',
  4. 'DB_NAME' => 'thinkcmf',
  5. 'DB_USER' => 'root',
  6. 'DB_PWD' => 'root',
  7. 'DB_PORT' => '3306',
  8. 'DB_PREFIX' => 'cmf_',
  9. //密钥
  10. "AUTHCODE" => '2oF6v4m67BdQnfwMSf',
  11. //cookies
  12. "COOKIE_PREFIX" => '03a9uH_',
  13. );

如果我们已经在配置文件中配置了额外的数据库连接信息,例如:

  1. return array(
  2. //数据库1
  3. 'DB_TYPE' => 'mysql',
  4. 'DB_HOST' => '127.0.0.1',
  5. 'DB_NAME' => 'thinkcmf',
  6. 'DB_USER' => 'root',
  7. 'DB_PWD' => 'root',
  8. 'DB_PORT' => '3306',
  9. 'DB_PREFIX' => 'cmf_',
  10. //密钥
  11. "AUTHCODE" => '2oF6v4m67BdQnfwMSf',
  12. //cookies
  13. "COOKIE_PREFIX" => '03a9uH_',
  14. //数据库2
  15. 'DB_CONFIG2' => array(
  16. 'db_type' => 'mysql',
  17. 'db_user' => 'root',
  18. 'db_pwd' => 'root',
  19. 'db_host' => '127.0.0.1',
  20. 'db_port' => '3306',
  21. 'db_name' => 'repast'
  22. ),
  23. );

二、实例化定义

  1. $User = M('User','cmf_','DB_CONFIG2');
  1. 作者:小夏