如何从Cake Shell读取数据库配置设置? [英] How Can I Read the DB Configuration Settings From a Cake Shell?

查看:89
本文介绍了如何从Cake Shell读取数据库配置设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个蛋糕shell做一个每晚的备份我的数据库使用mysqldump。我可以做一个shell脚本,但如果我可以把它绑定到一个CakePHP shell,那么我会得到它的工作在开发和活动服务器的额外的好处,如果我可以让它自动读取我的数据库配置设置。我会cron蛋糕shell和有一些安心,知道我频繁备份我的数据库。

I would like to write a cake shell to do a nightly backup of my database using mysqldump. I could do this as a shell script, but if I can cram it into a CakePHP shell, then I will get the added benefit of it working across both the development and live server, if I can get it to automagically read my database config settings. I will cron the cake shell and have some peace-of-mind knowing that I have frequent backups of my DB.

在我的shell我试图建立一个字符串以mysqldump --user =开头,我想从app / config / database.php获取用户名。如何获取database.php中的数据?

In my shell I'm trying to build up a string which starts with "mysqldump --user=" and I'd like to get the username from app/config/database.php. How can I get at the data in database.php?

推荐答案

在蛋糕2.1中,格式已更改为:

In cake 2.1 the format has changed to:

App::uses('ConnectionManager', 'Model');
$dataSource = ConnectionManager::getDataSource('default');
$username = $dataSource->config['login'];

这篇关于如何从Cake Shell读取数据库配置设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆