从PHP执行时,MySQL SELECT语句不起作用

I have the following piece of code, executing a pretty simple MySQL query:

$netnestquery = 'SELECT (`nested`+1) AS `nest` FROM `ipspace6` WHERE `id`<='.$adaddr.' AND `subnet`<='.$postmask.' AND `type`="net" AND `addr` NOT IN(SELECT `id` FROM `ipspace6` WHERE `addr`<'.$adaddr.' AND `type`="broadcast") ORDER BY `id`,`subnet` DESC LIMIT 1';

$netnestresults = mysql_query($netnestquery);
$netnestrow = mysql_fetch_array($netnestresults);
$nestlvl = $netnestrow['nest'];

echo '<br> NESTQ: '.$netnestquery;

Now, when I execute this in PHP, I get no results; an empty query. However, when I copy and paste the query echoed by my code (for debug purposes) into the mysql command line, I get a valid result:

mysql> SELECT (`nested` + 1) AS `nest` FROM `ipspace6` WHERE `id`<=50552019054038629283648959286463168512 AND `subnet`<=36 AND `type`='net' AND `addr` NOT IN (SELECT `id` FROM `ipspace6` WHERE `addr`<50552019054038629283648959286463168512 AND `type`='broadcast') ORDER BY `id`,`subnet` DESC LIMIT 1;
+------+
| nest |
+------+
|    1 | 
+------+
1 row in set (0.00 sec)

Can anybody tell me what I'm doing wrong? I can't put quotes around my variables, as then MySQL will try to evaluate the variable as a string, when it is, in fact, a very large decimal. I think I might just be making a stupid mistake somewhere, but I can't tell where.

dtl85148
dtl85148 乔丹,这是我的新询问。没有太大的不同,但它似乎工作:$netnestquery='SELECT子网,(嵌套+1)AS嵌套FROMipspace6WHEREid<='。$adaddr。'ANDsubnet<='。$postmask。'ANDtype=“net”ANDsubnetNOTIN(SELECT子网FROMipspace6WHEREaddr<='。$adaddr。'ANDtype=“broadcast”ANDsubnet>='。$postmask。')ORDERBYid,subnetDESCLIMIT1“;
大约 10 年之前 回复
douqiang3768
douqiang3768 Charles,如果没有PHP中的内置函数,有没有更好的方式与MySQL交互?我正在尝试开发一个用于跟踪子网划分和聚合的IPv6Web应用程序,并将这些数字存储为字符串会让MySQL感到震惊。
大约 10 年之前 回复
dongren1986
dongren1986 toolong
大约 10 年之前 回复
dongnao6858
dongnao6858 很高兴你能得到它。为了历史和孩子们,你能发布你必须做的事情吗?
大约 10 年之前 回复
douzhi3454
douzhi3454 总之,我通过以不同的方式重写我的查询来解决我的问题,PHP和MySQL似乎都喜欢这样。我给予乔丹接受的答案,因为他是最活跃的并且试图提供帮助。谢谢,全部!
大约 10 年之前 回复
doubanduo7620
doubanduo7620 愚蠢的错误#1:没有使用参数化查询。
大约 10 年之前 回复
dongpo7467
dongpo7467 单/双引号差异?html-tags标签你在浏览器中看不到输出结果查询?
大约 10 年之前 回复

3个回答



你可以修改一行来说明$ netnestresults = mysql_query($ netnestquery)或die(mysql_error()); </ p> \ n

它可能会给您一个未知错误,例如连接错误,缺少数据库等。</ p>
</ div>

展开原文

原文

Can you modify the line to say $netnestresults = mysql_query($netnestquery) or die(mysql_error());

It may be giving you an unknown error, such as a bad connection, missing DB, etc.

douyin4875
douyin4875 我尝试了你的新查询,但我仍然没有从MySQL获得任何结果。
大约 10 年之前 回复
dshun123456
dshun123456 对于咯咯笑,您可以将查询更改为:“SELECT(嵌套+ 1)AS嵌套FROM ipspace6 WHERE id <= $ adaddr AND subnet <= $ postmask AND type ='net'AND addr NOT IN(SELECT id FROM ipspace6 WHERE addr <$ adaddr AND type ='broadcast')ORDER BY id,subnet DESC LIMIT 1“;
大约 10 年之前 回复
dream2891
dream2891 Jordan,是的,工作正常,运行该查询时得到有效的结果。
大约 10 年之前 回复
dongpo9071
dongpo9071 你能从数据库中选择任何东西吗? 也许你可以“选择嵌套为嵌套从ipspace6限制0,1的巢”,看看是否有任何回来?
大约 10 年之前 回复
duanou2016
duanou2016 嗨乔丹,谢谢你的回复。 我试过了,我没有任何错误。 但是,当我这样做时:$ netnestrow = mysql_fetch_array($ netnestresults)或die(mysql_error()); 我得到一个空白页面。
大约 10 年之前 回复



执行 echo $ netnestquery </ code>
之前调用 mysql_query </ code>
还要添加一个模具 (mysql_error())那里。</ p>
</ div>

展开原文

原文

do an echo $netnestquery before calling mysql_query also add a die(mysql_error()) there.

WHERE `id`<=50552019054038629283648959286463168512

That's a pretty big number there.

PHP has issues with big numbers. The maximum size of an integer depends on how PHP was compiled, and if it's on a 64-bit system.

Have you checked that the variable containing that number hasn't been capped to a 32-bit or 64-bit integer? If it has been capped, you're going to need to take steps to make sure it's only being stored as a string in PHP. MySQL accepts strings that are entirely numeric as numbers without complaining.

(That being said, I'm not sure that MySQL can do anything with a number larger than 64-bits. The largest integer column is BIGINT, which is 64-bits. There's also NUMERIC, but it's treated as a floating point number, and that might not be what you want to do...)

doudiao2335
doudiao2335 查尔斯,我将这些数字存储在Decmial(39,0)UNSIGNED列中。 它似乎工作得很好,但我遇到了MySQL试图将这些数字解释为字符串的问题。 在这里查看我的另一个问题(关于这一点):stackoverflow.com/questions/2993828 / ...
大约 10 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐