Recently, due to project needs
You need to use the sleep function to regularly fetch a bunch of data from the database to perform certain operations.
The waiting time for sleep is at least an hour
Tested before
It is possible to use the sleep function to complete operations performed several hours later
But here comes the evil problem
After using sleep, the program found that it could not get the corresponding information from the database
Remove sleep
The result is normal
Depressed. . .
Does sleep affect the library reading operation? ! !
So for the convenience of testing
Just do sleep(10) and execute it in ten seconds
The result can read information from the database
But why can't sleep() read information after an hour?
For the convenience of testing, I read the library directly before the sleep statement, and read the library again after the sleep statement
Such as:
There should be some special characters that are not processed. You can use addslashes() to convert them.
If that doesn’t work, use base64_encode() to encrypt it and save it again.
When used, just take it out and use base64_decode() to decrypt it.
sql语句这样写select name for 表名 where...
然后读取第0个
或者你可以用函数
mysql_fetch_array
例子 2. mysql_fetch_array 使用 MYSQL_NUM
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf ("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>
例子 3. mysql_fetch_array 使用 MYSQL_ASSOC
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
}
mysql_free_result($result);
?>
例子 4. mysql_fetch_array 使用 MYSQL_BOTH
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("ID: %s Name: %s",......余下全文>>