Php 我得到了可靠的id#5
当我运行此查询时,我将获得资源id#5请尝试以下操作:Php 我得到了可靠的id#5,php,mysql,Php,Mysql,当我运行此查询时,我将获得资源id#5请尝试以下操作: $results=mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')"); if(!$results) { echo mysql_error(); } else {
$results=mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
if(!$results)
{
echo mysql_error();
}
else
{
echo $resulta;
}
旁注:您的代码易受sql注入攻击mysql.*
已被弃用。建议您使用pdo尝试以下方法:
$results=mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
if(!$results)
{
echo mysql_error();
}
else
{
echo $resulta;
}
$results = mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
if (!$results) {
echo mysql_error();
} else {
$data = mysql_fetch_assoc($results);
var_dump($data); //check all the data that is returned
}
旁注:您的代码易受sql注入攻击
mysql.*
已被弃用。建议您使用pdo,或者您也可以尝试这种方式
$results = mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
if (!$results) {
echo mysql_error();
} else {
$data = mysql_fetch_assoc($results);
var_dump($data); //check all the data that is returned
}
$results=mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
while($data=mysql_fetch_row($results)){
//your answer
}
是的,如上所述,您的代码容易受到sql注入的攻击。或者您也可以尝试这种方法
$results=mysql_query("SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')");
while($data=mysql_fetch_row($results)){
//your answer
}
是的,如上所述,您的代码容易受到sql注入的攻击。您需要获取结果以显示。请尝试
print\r(mysql\u fetch\u assoc($resulta))
而不是echo$resulta代码>。您可能应该从一本好书/教程中学习PHP。您需要获取显示结果
而不是echo$resulta代码>。您可能应该从一本好书/教程中学习PHP。我得到这个==>array(1){[“TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00')”]=>string(5)“79259”}我需要从结果输出得到以秒为单位的时间(79259){这是您想要的结果。使用打印($data)
可获得更清晰的图片@veerendrareddyI得到这个==>array(1){[“TIMESTAMPDIFF(秒,'2007-12-30 12:01:01','2007-12-31 10:02:00')”]=>string(5)“79259”}我需要从结果输出得到以秒为单位的时间(79259)}这是您想要的结果。使用打印($data)
可获得更清晰的图片@韦伦德雷迪