基于环境自动配置数据库连接

时间:2017-02-20 13:57:24

标签: php database laravel heroku database-connection

我知道这是错的,但是我已经尝试过谷歌这种任务了,我一无所获。

目标

我尝试根据我的Laravel环境创建# get all the terms which are in the training df, but not in the test df terms <- colnames(train.df[,which(!colnames(train.df) %in% colnames(test.df))]) # weight is set, this is just in case that weightTfIdf was used, otherwise it should be 0 weight <- 0.000000001 # now create a new matrix with the missing terms amat <- matrix(weight, nrow = nrow(test.df), ncol = length(terms)) colnames(amat) <- terms rownames(amat) <- rownames(test.df) # create a new test df with the original values plus the new matrix with the missing terms test.df.fixed <- cbind(test.df[,which(colnames(test.df) %in% colnames(train.df))],amat) test.df.fixed <- test.df.fixed[, sort(colnames(test.df.fixed))] ,我将在本地环境和Heroku生产环境之间正确设置数据库连接。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

      if (string.Charecter.count==0) { //Delete any cases
       if(range.length > 1){
          //Delete whole word
       }
       else if(range.length == 1){
          //Delete single letter
       }
       else if(range.length == 0){
          //Tap delete key when textField empty
       }  
    }  
    return true
}

2 个答案:

答案 0 :(得分:1)

听起来 Cascading config 包对您来说非常有用。 Laravel 4有一些非常类似的东西。

您可以为Heroku环境提供 config.local 文件夹和 config.production 文件夹。

示例文件夹配置

config/ (production)

├── database.php

config.local/ (local)

├── database.php

config / database.php(生产)

...
connections' => [
    'mysql'       => [
        'driver'      => 'mysql',
        'host'        => 'Heroku Host',
        'database'    => 'Heroku Database',
        'username'    => 'Heroku Username',
        'password'    => 'Heroku Password',
        'unix_socket' => 'Heroku Socket',
    ],      
],
...

config.local / database.php(local)

...
connections' => [
    'mysql'       => [
        'driver'      => 'mysql',
        'host'        => env('DB_HOST'),
        'database'    => env('DB_DATABASE'),
        'username'    => env('DB_USERNAME'),
        'password'    => env('DB_PASSWORD'),
    ],      
],
...

答案 1 :(得分:1)

你可以定义另一个以exmaple mysql-heroku命名的连接,然后在你的模型中你可以C:\