gpt4 book ai didi

mysql - SQL 错误 : USE `most` ; SELECT `item_name` , SUM (`stock_invent` ) AS `Total Items` FROM inventory GROUP BY `item_name

转载 作者:行者123 更新时间:2023-11-29 23:20:41 24 4
gpt4 key购买 nike

我试图通过 SQL 打印出项目的列表总数。它在 phpmyadmin 上运行良好,但在 Dreamweaver 中则不然。我不知道我的 SQL 有什么问题。有人可以帮助我吗?

mysql_select_db($database_dbcon, $dbcon);

$query_Recordset1 = "USE `most`; SELECT `item_name`, SUM(`stock_invent`) AS `Total Items` FROM inventories GROUP BY `item_name`";

$Recordset1 = mysql_query($query_Recordset1, $dbcon) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

我收到了这样的消息:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT item_name, SUM(stock_invent) AS Total Items FROM inventories GROUP ' at line 1

最佳答案

use 命令在 phpMyAdmin(以及 mysql 的命令行工具)中用于选择要对其运行查询的数据库。在 PHP 中,您不应该需要它 - 这就是 mysql_select_db 的用途:

mysql_select_db('most', $dbcon);

$query_Recordset1 = "SELECT `item_name`, SUM(`stock_invent`) AS `Total Items` FROM inventories GROUP BY `item_name`";

关于mysql - SQL 错误 : USE `most` ; SELECT `item_name` , SUM (`stock_invent` ) AS `Total Items` FROM inventory GROUP BY `item_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27334883/

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