douwen9534 2017-04-06 11:52
浏览 60

Codeigniter命令行无法插入数据库

I have this function on 'myproject/controllers/sample.php'

public function callTest() 
{
    $this->load->database();
    $this->db->query("INSERT INTO table_name (client_id, subscription_id, platform, device) VALUES (1, 1, 1, 1)");

    $this->load->view('sample');
}

Whenever I run it on the browser (localhost/index.php/sample/callTest), it successfully runs and inserts the data on the table, but when I use command line (php index.php sample callTest), the SQL won't run.

I removed the database part and it shows the code for the view, which I think is correct. But if I put a database logic to it, it won't run and the output is blank. No error logs also.

Am I doing something wrong? Am I missing an argument? My codeigniter version is 2.2.6. This is my reference https://www.codeigniter.com/userguide2/general/cli.html

Edited: Aril 17,2017

I just figured out that in some of environment, the command line above works. I suspect that the cause of this was me converting PHP 5.5 to 5.6 in Ubuntu 14, some of the dependencies might not be configured correctly.

  • 写回答

1条回答 默认 最新

  • dongzhang5787 2017-04-17 04:52
    关注

    You need to specify controller and function name as well,

    Example

    php index.php/sample/callTest
    

    Also you need to set one config variable as below

    $config['uri_protocol'] = 'AUTO'
    

    Read the document answer is hidden there.

    Now normally you would visit the your site using a URL similar to this:

    example.com/index.php/tools/message/to

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化