以下SQL语句的update语句无效。
执行后说:
Query performed correctly: 0 row(s) affected.
每次调用后,timescount列应增加1,但不会发生。我需要你专业的眼睛仔细审查这个陈述。我还在代码下面显示了我的数据库模式。
require '15_12.php';
//Now, let us create an instance of mydb.
$mydb = new mydb ("localhost","root","");
//Select a database to use.
$mydb->selectdb ("myquotes");
//Then, let's try to return a row set.
$adata = $mydb->getrows ("SELECT url_string FROM tshirt WHERE timescount = 0 ORDER BY url_id ASC LIMIT 3");
for ($i = 0; $i < count ($adata); $i++){
$result = PIPHP_GetLinksFromURL($adata[$i]);
echo "<ul>";
for ($j = 0 ; $j < count($result) ; ++$j) {
echo "<li>$result[$j]</li>";
}
//Now, hold the row in a variable
$url_escaped = $adata[$i];
//Now, let's perform an action.
$mydb->execute ("UPDATE tshirt SET timescount=timescount+1 WHERE url_string='url_escaped'");
}
数据库结构
CREATE TABLE IF NOT EXISTS `tshirt` (
`url_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`url_string` varchar(2048) NOT NULL,
`timescount` int(11) unsigned NOT NULL,
`dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`url_id`)
)
答案 0 :(得分:3)
你错过了变量中的$
,导致它被用作字符串文字:
$mydb->execute ("UPDATE tshirt SET timescount=timescount+1 WHERE url_string='url_escaped'");
^^^^
HERE
应该是
$mydb->execute ("UPDATE tshirt SET timescount=timescount+1 WHERE url_string='$url_escaped'");