Codeigniter返回值

发布于 2024-12-28 17:41:57 字数 335 浏览 0 评论 0原文

我是 Codeigniter 和 PHP 的新手。

在做一些操作时我有一些疑问,特别是在数据库中。

$get = "select filed_1 from tbl_ctc where ctc=?";
$get = $this->db->query($get,array($ctc_n));

if ($get)
{

 //do some operations 
}
else
{
 //do some another operations 

}

如果成功的话$get的返回值是多少?

期待意见&建议[也反对]

谢谢。

I am new to Codeigniter and PHP..

while doing some operations i have some doubts ,especially in the database libraries .

$get = "select filed_1 from tbl_ctc where ctc=?";
$get = $this->db->query($get,array($ctc_n));

if ($get)
{

 //do some operations 
}
else
{
 //do some another operations 

}

What will be the return value of $get if it is success ?

Expecting opinion & suggestion [downvotes too]

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2025-01-04 17:41:58

您期待什么“意见和建议”?

当您使用读取查询(例如选择)时,query()方法返回一个结果对象,而使用写入查询(例如插入或插入)更新)它返回 TRUE 或 FALSE。

在 SELECT 的情况下,即,您可能想检查它是否有任何结果:

$query = $this->db->query($select_query);
if($query->num_rows() > 0)
{}

而在 INSERT 的情况下,例如:

$query = $this->db->query($insert_query);
if($query)   // or if(FALSE !== $query)
{}
else
{}

请注意,如果您使用的是 Active Record,您将获得 result() / row()result_array() / row_array() 方法将返回完整对象/数组或空数组一个,所以你需要检查那些值代替。

What "opinions and suggestions" do you expect?

The query() method returns a result object when you use read queries (like a select), while with write queries (like an insert or update) it returns TRUE or FALSE.

In case of a SELECT, i.e., you might want to check if it has any result:

$query = $this->db->query($select_query);
if($query->num_rows() > 0)
{}

While, in case of an INSERT for ex.:

$query = $this->db->query($insert_query);
if($query)   // or if(FALSE !== $query)
{}
else
{}

Note that if you are using Active Record, you'll have the result() / row() and result_array() / row_array() methods that will return either a full object/array or an empty one, so you'll need to check for those values instead.

故人爱我别走 2025-01-04 17:41:58

结果将是一个对象。您必须更进一步才能获得预期值,例如

$get = $this->db->query($get,array($ctc_n));
$res = $get->result_array();

echo $res[0]['filed_1'];

请参阅 Active Record Class 和用户指南中的示例以供进一步参考。

The result will be an object. You have to go one step further to get the expected value, e.g.

$get = $this->db->query($get,array($ctc_n));
$res = $get->result_array();

echo $res[0]['filed_1'];

See Active Record Class and examples from the user guide for further reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文