PHP-Codeigniter活动记录和MySQL

前端之家收集整理的这篇文章主要介绍了PHP-Codeigniter活动记录和MySQL 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在我的codeigniter应用程序的模式下使用Active Record运行查询,查询看起来像这样,

public function selectAllJobs()
{
    $this->db->select('*')
             ->from('job_listing')
             ->join('job_listing_has_employer_details','job_listing_has_employer_details.employer_details_id = job_listing.id','left');
             //->join('employer_details','employer_details.users_id = job_listing_has_employer_details.employer_details_id');

    $query = $this->db->get();
    return $query->result_array();
}

这将返回一个看起来像这样的数组,

    [0]=>
  array(13) {
    ["id"]=>
    string(1) "1"
    ["job_titles_id"]=>
    string(1) "1"
    ["location"]=>
    string(12) "Huddersfield"
    ["location_postcode"]=>
    string(7) "HD3 4AG"
    ["basic_salary"]=>
    string(19) "£20,000 - £25,000"
    ["bonus"]=>
    string(12) "PHP,html,j"
    ["benefits"]=>
    string(11) "Compnay Car"
    ["key_skills"]=>
    string(1) "1"
    ["retrain_position"]=>
    string(3) "YES"
    ["summary"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["description"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["job_listing_id"]=>
    NULL
    ["employer_details_id"]=>
    NULL
  }
}

job_listing_id和loyal_details_id返回为NULL,但是如果我在PHPmyadmin中运行sql,则会得到完整的结果集,我在PHPmyadmin中运行的查询是,

    SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id`
LIMIT 0,30

我得到不同结果的原因是什么?

最佳答案
运行$this-> db-> last_query()并检查差异.这是一个非常有用的调试工具.

当然,限制会产生影响,但我忽略了这一点.

似乎在PHPmyadmin中的查询中,“ ON”没有第二部分.
我认为您在PHPmyadmin中的查询应为:

SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id` =  = `job_listing`.`id`

尽管对方说了什么,您仍应使用result_array.

原文链接:https://www.f2er.com/mysql/532109.html

猜你在找的MySQL相关文章