gpt4 book ai didi

mysql - Zend 框架 - mysql 查询

转载 作者:行者123 更新时间:2023-11-30 00:21:47 27 4
gpt4 key购买 nike

$xyz = mysql_fetch_array(mysql_query('select sum(value) points where userId = $userIdDB'))['suma'];

该查询在 zend 框架中看起来如何?我需要从数据库中选择记录总和作为 int。还有一个问题:我可以进行 mysql 查询吗?我实际上对 zend 没有任何了解,所以请您提供完整的解释。zend 中的 mysql 连接怎么样?

最佳答案

In ZEND

$select = $db->select()
->from('points',array(new Zend_Db_Expr('sum(value)')))
->where('userId = ?', $userIdDB);

添加表达式列时

Columns in SQL queries are sometimes expressions, not simply column names from a table. Expressions should not have correlation names or quoting applied. If your column string contains parentheses, Zend_Db_Select recognizes it as an expression.

You also can create an object of type Zend_Db_Expr explicitly, to prevent a string from being treated as a column name. Zend_Db_Expr is a minimal class that contains a single string. Zend_Db_Select recognizes objects of type Zend_Db_Expr and converts them back to string, but does not apply any alterations, such as quoting or correlation names.

EXAMPLE IN ZEND

// Build this query using Zend_Db_Expr explicitly:
// SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax
// FROM "products" AS p

$select = $db->select()
->from(array('p' => 'products'),
array('product_id',
'cost_plus_tax' =>
new Zend_Db_Expr('p.cost * 1.08'))
);

关于mysql - Zend 框架 - mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23172262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com