doulin6761 2012-09-05 21:48
浏览 47
已采纳

使用CakePHP如何从数据库导出数据。 不包括架构

In my CakePHP App, I have exported my database schema, however now I just need the data that I will use to pre-populate for the user.

Will not work as it generates only the schema:

cake schema generate

Looking for a solution that will generate an Insert or Update of current data in the db.

Update:

This is for an installer that I am writing. When a user completes the installation it should populate the db with data required for the app.

  • 写回答

2条回答 默认 最新

  • dqmfo84644 2012-09-06 18:34
    关注

    NOTE: The OP is not asking how to get data from the database command line per se. He wants to create an installer that will populate a database when the user runs the installation. For example, when you install WordPress, you are not going to run mysqldump, right? The application takes care of it. This is a similar situation.

    The easiest way to do this is to use the models that come with the application.

    Check to see if the system is installed, if not run the following:

    1. open the installer asking for the DB credentials in a form
    2. use the credentials to create the database
    3. if the database cannot be created, explain that they must create the database manually
    4. save the credentials to the correct location in the database.php config
    5. create the schema from within the controller
    6. once the schema is built, load all of the pre-set data from the model

    Take advantage of the install controller / db models within cake to do the lifting. So for example, if you want to pre-load some configuration settings:

    $config['Config']['setting_1'] = 'foo';
    $config['Config']['setting_2'] = 'bar';
    
    $this->loadModel('Config');
    $this->Config->create();
    $this->Config->save($config);
    

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line