Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将数组的整数添加到变量_Php_Mysql_Pdo - Fatal编程技术网

Php 如何将数组的整数添加到变量

Php 如何将数组的整数添加到变量,php,mysql,pdo,Php,Mysql,Pdo,每次更新时,tcount保留1。为什么会出现这种情况?如果使用int,就不需要像这样在变量上加引号 mysql (table name is accessNum) is pagename(varchar(255)) = index.html, today(date) = 2015-08-31, tcount(int(11)) = 1, totalcount(int(11)) = 1, 在SELECT查询中,不需要在列名周围加引号 if (sizeof($stmt) != 0) { $c

每次更新时,tcount保留1。为什么会出现这种情况?

如果使用int,就不需要像这样在变量上加引号

mysql (table name is accessNum) is
pagename(varchar(255)) = index.html,
today(date) = 2015-08-31,
tcount(int(11)) = 1,
totalcount(int(11)) = 1,

SELECT
查询中,不需要在列名周围加引号

if (sizeof($stmt) != 0) {
    $counter = $record['tcount'];
    $counter++;
    $dbh->exec("update accessNum set tcount = $counter where pagename = '$pagename'");
}
$stmt = $dbh->query("select tcount from accessNum where pagename = '$pagename'");
此外,在
UPDATE
查询中,不需要在数字周围加引号

if (sizeof($stmt) != 0) {
    $counter = $record['tcount'];
    $counter++;
    $dbh->exec("update accessNum set tcount = $counter where pagename = '$pagename'");
}
$stmt = $dbh->query("select tcount from accessNum where pagename = '$pagename'");

总是用反勾号转义列和表名,用引号转义值。在MySQL中,它们是完全不同的。这应该起作用:

$dbh->exec("update accessNum set tcount = $counter where pagename = '$pagename'");

结束报价表
'tcount'
!!从查询中选择“tcount”将直接选择字符串
“tcount”
。它将不会获取该列的值。这就像执行
选择1
。对不起,我知道会发生什么。