[英]MySQL and Do While loop timing out
This is timing out without echo-ing anything as well as not inserting into database. 这是超时的,没有回显任何内容,也没有插入数据库。 Can't see why.
不明白为什么。 Any ideas?
有任何想法吗?
Note It's to simply generate a number of code numbers, I'm aware that it's simple and insecure, it's being done on localhost only and the connection values are sound. 注意它只是简单地生成许多代码号,我知道它是简单且不安全的,它仅在localhost上完成并且连接值正确。
function populate_codes(){
$con = mysql_connect(dbhost,dbuser,dbpass);
mysql_select_db(dbname);
$i = 0;
do{
$code = rand(10000000,99999999);
$check = mysql_query('SELECT * FROM '.dbcodetable.' WHERE code = $code',$con);
if(!$check){
$insertcode = mysql_query('INSERT INTO '.dbcodetable.' (code,status) VALUES ($code,1)',$con);
if($insertcode){
echo $i.' - '.$code.'<br />';
$i++;
}
}
}
while($i <= 1999);
echo "------------------------<br /><strong>Complete</strong>";
}
You: 您:
$i
to 0 $i
设置为0 false
false
$i
$i
$i
is incremented beyond 1999 $i
超过1999年为止 The problem is that your 4th step always succeeds . 问题是您的第四步总是成功 。 The query always executes successfully,
mysql_query
always returns a result set . 查询总是成功执行,
mysql_query
总是返回结果集 。 You have to inspect the result set to see what's in it, not just test it against == false
. 您必须检查结果集以查看其中的内容,而不仅仅是对
== false
测试。 So, $i
never increments. 因此,
$i
从不递增。
You also want to increment $i
outside all those ifs, or have a general protection against infinite loops. 您还希望在所有这些
$i
之外增加$i
,或者对无限循环有一般的保护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.