将自动增量 id mysql 插入到 mysqli
Inserting autoincrement id mysql to mysqli
首先:我在 google 和 Whosebug 中搜索:在 mysql、found this on SO but it was not helpful 中插入自动递增 ID。我发现的其他所有内容都是针对 mysqli->insert_id;
如果我在寻找解决方案时遗漏了一点,我会在评论中给出正确的 link。
我正在尝试 "translate" 旧的 mysql_ 函数到 mysqli_ 函数。
假设我的旧查询是:
mysql_query("INSERT INTO `bugtracker`
(`id`, `date`, `workerid`, `currURL`, `prevURL`, `bugTitle`, `bugDesc`) VALUES
(NULL, '".time()."', '$worker', '$clean[currURL]', '$clean[prevURL]', '$clean[bugTitle]', '$clean[bugDesc]');");
为了理解:
($clean[currURL]
= mysql_real_escape_string($_POST['currURL']);
)
新的必须是这样的:
$query = "INSERT INTO `bugtracker` (`id`, `date`, `workerid`, `currURL`, `prevURL`, `bugTitle`, `bugDesc`) VALUES (?, ?, ?, ?, ?, ?, ?)";
$statement = $mysqlicon->prepare($query);
$statement->bind_param('iiissss', 'NULL??', time(), $worker, $_POST['currURL'], $_POST['prevURL'], $_POST['bugTitle'], $_POST['bugDesc']);
$statement->execute();
$statement->close();
问题:无论如何我都没有尝试 运行 我的查询,因为我很好奇我应该如何将前面的 "NULL" 插入到我在 mysqli 中的自动增量 ID。我应该忽略并将其留空吗?只是不要在 $query
和 bind_param
?
中显示它
Table 结构顺序如下:
id
(int11), date
(int11), workerid
(int11), currURL
(varchar), prevURL
(varchar), bugTitle
(varchar), bugDesc
(文本)
请勿在您的声明中指定此列 (id)。
首先:我在 google 和 Whosebug 中搜索:在 mysql、found this on SO but it was not helpful 中插入自动递增 ID。我发现的其他所有内容都是针对 mysqli->insert_id; 如果我在寻找解决方案时遗漏了一点,我会在评论中给出正确的 link。
我正在尝试 "translate" 旧的 mysql_ 函数到 mysqli_ 函数。
假设我的旧查询是:
mysql_query("INSERT INTO `bugtracker`
(`id`, `date`, `workerid`, `currURL`, `prevURL`, `bugTitle`, `bugDesc`) VALUES
(NULL, '".time()."', '$worker', '$clean[currURL]', '$clean[prevURL]', '$clean[bugTitle]', '$clean[bugDesc]');");
为了理解:
($clean[currURL]
= mysql_real_escape_string($_POST['currURL']);
)
新的必须是这样的:
$query = "INSERT INTO `bugtracker` (`id`, `date`, `workerid`, `currURL`, `prevURL`, `bugTitle`, `bugDesc`) VALUES (?, ?, ?, ?, ?, ?, ?)";
$statement = $mysqlicon->prepare($query);
$statement->bind_param('iiissss', 'NULL??', time(), $worker, $_POST['currURL'], $_POST['prevURL'], $_POST['bugTitle'], $_POST['bugDesc']);
$statement->execute();
$statement->close();
问题:无论如何我都没有尝试 运行 我的查询,因为我很好奇我应该如何将前面的 "NULL" 插入到我在 mysqli 中的自动增量 ID。我应该忽略并将其留空吗?只是不要在 $query
和 bind_param
?
Table 结构顺序如下:
id
(int11), date
(int11), workerid
(int11), currURL
(varchar), prevURL
(varchar), bugTitle
(varchar), bugDesc
(文本)
请勿在您的声明中指定此列 (id)。