繁体   English   中英

如何从Codeigniter中的mysql获取int字段名称的值?

[英]how to get value of int field name from mysql in codeigniter?

我试图从其中某些字段名称为整数的表中获取值。

下面是我的桌子

|--------------------|
|  id   |  1   | 2   |
|--------------------|
|  1    |  6   | 3   |
|  2    |  8   | 6   |
----------------------

我在普通的php中尝试了以下代码,但在codeigniter中无法正常工作

 mysqli_query($conn,'select `1`from table')  //normal php working.
 $this->db->query('select `1` from table'); // not working in ci.

有两种方法可以使用活动记录或SQL查询来运行查询。

function get()
{
    $query = $this->db->get('table',1);
    return $query->result();
}

要么

$query=$this->db->query('select table.1 as one from table');
$query->result();

您需要最后调用result()

//get results
$result = $this->db->query('select table.`1` from table')->result();

//parse results
foreach ($result as $row) {
    echo $row; //complete row
    //OR
    echo $row->1; //cell value
}

尝试这个: -

 $this->db->query('select 1 from table'); OR 

或尝试以下方法:-

 $this->db->query('select "'.1.'" from table');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM