- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
获得三个表(博客、标签和博客标签),所有 AI 和 ID 设置为主键。我正在制作一个标记系统来跟踪我的网站(本地主机)。下面的代码可以工作,但是 mysql_insert_id 似乎不够可靠,因为我得到了一些重复的行,并且其中偶尔有 0 值。
/// inserts the blog into blog table.
$insert = mysql_query("INSERT INTO blogs (id, url, user, pass, dname, islocal, cat2post) VALUES ('', '$blog', '$bloguser', '$blogpassword', '','NO','$_POST[cat2blog]')")or die( 'Error: ' . mysql_error());
$taggit1 = mysql_insert_id();
$page->content .= "Success - External blog Added!
";
/// let's see what tags we have and explode them.
//$tags = $_POST['tags'] which is an array of words seperated by comma
$tags = 'fishing';
$pieces = explode(",", $tags);
/// go through the tags and add to tags table if needed.
foreach ($pieces as $l){
$l = trim($l);
$query = "SELECT id FROM tags WHERE tag = '$l'";
$result = mysql_query($query) or die( "Error: " . mysql_error() . " in query $query");
$row = mysql_fetch_array($result);
$taggit2 = $row[0];
if ($taggit2 == '') {
$insert2 = mysql_query("INSERT INTO tags (id, tag) VALUES ('','$l')")or die( 'Error: ' . mysql_error());
$taggit2 = mysql_insert_id();
$page->content .= "This tag didn't exist - so I inserted a new tag
";
}
/// for each tag we have, let's insert the blogstags table so we can reference which blog goes to which tag. Blogstags_id should map to the id of the blog.
$insert3 = mysql_query("INSERT INTO blogstags (id, tag_id, blogstags_id) VALUES ('','$taggit2','$taggit1')")or die( 'Error: ' . mysql_error());
}
我想我需要一个与 mysql_insert_id 不同的解决方案 - 想法?有建议吗?
根据要求的表结构:
CREATE TABLE IF NOT EXISTS `blogs` (
`id` int(11) NOT NULL auto_increment,
`url` text NOT NULL,
`user` text NOT NULL,
`pass` text NOT NULL,
`dname` text NOT NULL,
`islocal` varchar(3) NOT NULL,
`cat2post` int(11) NOT NULL,
KHÓA CHÍNH (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
CREATE TABLE IF NOT EXISTS `blogstags` (
`id` int(11) NOT NULL auto_increment,
`tag_id` int(11) NOT NULL,
`blogstags_id` int(11) NOT NULL,
KHÓA CHÍNH (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `tags` (
`id` int(11) NOT NULL auto_increment,
`tag` text NOT NULL,
KHÓA CHÍNH (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
1 Câu trả lời
mysql_insert_id()
工作正常。问题可能是您正在使用持久连接。对于持久连接,可能会发生各种奇怪的并发问题。除非你真的非常需要,否则不要使用它们。
关于php - 帮我删除 mysql_insert_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972686/
我对此还很陌生。有没有办法在不更改数据库的情况下获取最后一个自动增量ID? $check = mysql_insert_id(); 我尝试了 Max(),但它给出了几乎相同的结果...... 最佳答案
这是我正在使用的代码,该代码只是通过两种不同的方法获取相同的值,但 mysql_insert_id() echo 没有给出输出。 由->echo mysql_insert_id()给出的值;是 0 谁
我们知道 mysql_insert_id() 会给出最后插入的 ID,但我想知道在下面的情况下我们是否会遇到问题。 UserA -> 调用将 ROW 插入 TABLE 并获取插入的 ID 的函数 执行
错误信息: mysql_insert_id() expects parameter 1 to be resource, boolean given 当我不传递参数时,我收到此错误消息: Warnin
我正在尝试向 mysql 数据库添加一条记录,然后立即检索该记录 ID。我想使用 mysql_insert_id() 但我想知道它是提取最后一条记录还是您插入的最后一条记录? 我在想,如果网站的两个用
我有以下代码: $sql = "INSERT INTO table VALUES ('', ...)"; $result = mysql_query($sql, $link) or die(mysql
在我的表单通过 ajax 和表单验证 (jquery.validationEngine) 提交后,我试图获取一个值 (mysql_insert_id) 但没有成功.. $(document).read
我有 3 个这样结构的表, employee > id (PK), name family > family_id (PK), id (employee PK) father > father_id
根据 PHP 文档,mysql_insert_id 从 mysql 表中获取最后插入的 id。 我的问题是,如果我有一个每秒向数据库插入超过 2 行的网站,我可以使用 mysql_insert_id
我发誓我已经在这个网站和其他网站上的所有其他类似问题上倾注了很多……但我想我只是想念一些东西。希望有人可以指出一个愚蠢的错误,那就是我的大脑对我隐藏了。 :) 我的脚本将表单中的值插入称为“ note
根据 PHP 文档,mysql_insert_id 从 mysql 表中获取最后插入的 id。 我的问题是,如果我有一个网站每秒向数据库插入超过 2 行,我可以使用 mysql_insert_id 并
根据 PHP 文档,mysql_insert_id 从 mysql 表中获取最后插入的 id。 我的问题是,如果我有一个网站每秒向数据库插入超过 2 行,我可以使用 mysql_insert_id 并
获得三个表(博客、标签和博客标签),所有 AI 和 ID 设置为主键。我正在制作一个标记系统来跟踪我的网站(本地主机)。下面的代码可以工作,但是 mysql_insert_id 似乎不够可靠,因为我得
我有一个 PHP 脚本,可以将数据插入到 mysql 数据库中。该表有一个自动增量列。 我想使用 mysql_insert_id() 函数来获取最后插入记录的值。 由于某种原因,这会返回值 0,其中
好吧,不知道这在实践中是否像理论上一样简单,但我想知道。 我在该查询中有一个 INSERT 查询,我想提取 AUTO_INCRMENT 值,然后在同一查询中重用它。 例如 //values to be
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我用 PHP 编写了以下 sql 语句。 $sql='INSERT INTO pictures (`picture`) VALUES ("'.$imgs[$i]['name'].'",)'; $db-
我正在尝试获取行的自动递增列。代码将解释,但基本上我正在尝试将一行插入名为订单的表中,然后我想获取自动递增的数字。这是我的 PHP。 prepare($q); $ps->execute();
我想我在一些 PHP 代码中遇到了竞争条件,mysql_insert_id() 返回 0 - 但我无法弄清楚原因。 $insertsess=mysql_query("insert into cior_
我需要从我的数据库表中检索自动递增字段。我尝试了以下但 $id 总是空的。 插入也有效。 我的表格如下:idint(9) NOT NULL auto_increment, 并且id被设置为主 我做错了
Tôi là một lập trình viên xuất sắc, rất giỏi!