gpt4 book ai didi

PHP MYSQL 查询在 PHP 中不起作用,但在 PHPMyAdmin 中起作用

转载 作者:行者123 更新时间:2023-11-29 06:35:44 25 4
gpt4 key购买 nike

<分区>

我有一个在 PHPMyAdmin 中成功运行的 MYSQl 查询。然而,当试图将它作为字符串存储在 PHP 变量中,然后使用 my_sqli 查询时,它给了我一个“boolean false”。我该怎么做才能使它正常工作?我有一种感觉,它可能与查询本身中的某些字符序列有关,这些字符序列与 PHP 中的字符串标准相冲突。

PHP代码:

<?php
$query =
"SET @pro_today = (SELECT count(*)
FROM `subscriptions`
WHERE CAST(created_at as DATE) = CAST(now() as DATE)
AND cancelled = 0
AND subscription_id != ''
AND plan = 'pro');

SET @pro_this_week = (SELECT count(*)
FROM `subscriptions`
WHERE WEEKOFYEAR(created_at)= WEEKOFYEAR(NOW())
AND cancelled = 0
AND subscription_id != ''
AND plan = 'pro');

SET @pro_this_month = (
SELECT count(*)
FROM `subscriptions`
WHERE MONTH(created_at)= MONTH(NOW())
AND cancelled =0
AND subscription_id !=''
AND plan = 'pro');

SET @single_event_today = (SELECT count(*)
FROM `subscriptions`
WHERE CAST(created_at as DATE) = CAST(now() as DATE)
AND cancelled = 0
AND subscription_id != ''
AND plan = 'single-event');

SET @single_event_this_week =
(SELECT count(*)
FROM `subscriptions`
WHERE WEEKOFYEAR(created_at)= WEEKOFYEAR(NOW())
AND cancelled = 0
AND subscription_id != ''
AND plan = 'single-event');

SET @single_event_this_month = (SELECT count(*)
FROM `subscriptions`
WHERE MONTH(created_at)= MONTH(NOW())
AND cancelled = 0
AND subscription_id != ''
AND plan = 'single-event');

UPDATE statistics
SET statistics.single_event_today = @single_event_today,
statistics.single_event_this_week = @single_event_this_week,
statistics.single_event_this_month = @single_event_this_month,

statistics.premier_today = @pro_today,
statistics.premier_this_week = @pro_this_week,
statistics.premier_this_month = @pro_this_month,

statistics.revenue_today = ((@pro_today * 8 ) + (@single_event_today * 25)),
statistics.revenue_this_week = ((@pro_this_week * 8)+(@single_event_this_week * 25)),
statistics.revenue_this_month = ((@pro_this_month * 8)+(@single_event_this_month * 25));";

doQuery($query);

function doQuery($query)
{
$con = mysqli_connect(//correct connection settings);

if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL : " . mysqli_connect_error();
}

$result = mysqli_query($con , $query);
mysqli_close($con);

if($result)
{
echo "Success";
}
else{
var_dump($result);
}
}

?>

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