doutenglou6588 2010-10-23 17:28 采纳率: 0%
浏览 47
已采纳

Code Igniter Load Database似乎停止了进程线程

I've just set up a simple PHP Code Igniter project on a Windows 7 box, IIS 7, Fast CGI, no modules.

when I load up database in one of the function of a Model class by doing such this->load->database() the thread seem to stop on that particular line. None of the subsequent operations are done.

class Account_model extends Model {

  var $userId = '';
  var $userName = '';
  var $requestToken = '';
  var $accessToken = '';
  var $enabled = false;
  var $startOfDay;
  var $endOfDay;

  function Account_model() {
      parent::Model();
  }

  function get($userId) {
      $this->load->database();
      $query = $this->db->get_where('accounts', array('userId' => $userId), 1, 0);
      return $query->result();
  }

  function insert() {
      $this->load->database();
      // ** stop **
      $this->db->insert('accounts', $this); //never gets to this
  }
}

If I simply ommit that line altogether, I get a php exception undefined variable $db in model.

The caller controller:

class SignUp extends Controller {

  function SignUp() {
      parent::Controller();
  }

  function createUser() {
      echo 'processing';

      $this->load->model('Account_model');

      $this->Account_model->userId = 'asd';
      $this->Account_model->userName = 'test_user_pls_delete';
      $this->Account_model->enabled = true;
      $this->Account_model->startOfDay = time();
      $this->Account_model->insert();

      echo 'done'; // never gets to this
  }
}

I've verified the database configuration is correct (host name, driver, etc), and able to connect to the database server from the machine using MySQL workbrench.

$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "{omitted}";
$db['default']['username'] = "{omitted}";
$db['default']['password'] = "{omitted}";
$db['default']['database'] = "{omitted}";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

The database table name: accounts

  • Id int(11) primary key auto_increment
  • UserId varchar(255) utf8_general_ci
  • userName varchar(255) utf8_general_ci
  • requestToken varchar(255) utf8_general_ci
  • AccessToken varchar(255) utf8_general_ci
  • Enabled tinyint(1)
  • startOfDay time
  • endOfDay time

Any ideas on how to fix this?

  • 写回答

3条回答 默认 最新

  • douhu8851 2010-10-24 17:42
    关注

    Hmmm... here is my model..

    class Account_model extends Model {
    
    function Account_model() {
        // Call the Model constructor
        parent::Model();
        $this->db = $this->load->database('default', TRUE);
    }
    
    function showTables() {
        $query = "show tables";
        $rs = $this->db->query($query);
        return $rs->result_array();
    }
    

    load the database in $db, so $db can process the query.

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

报告相同问题?

悬赏问题

  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接