Tagged Questions
171
votes
7answers
152k views
“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either:
"ON ...
7
votes
6answers
7k views
How to include a PHP variable inside a MySQL insert statement
I'm trying to insert values in the contents table. It works fine if I do not have a PHP variable inside VALUES. When I put the variable $type inside VALUES then this doesn't work. What am I doing ...
26
votes
9answers
13k views
MySQL Conditional Insert
I am having a difficult time forming a conditional INSERT
I have x_table with columns (instance, user, item) where instance ID is unique. I want to insert a new row only if the user already does not ...
6
votes
4answers
13k views
MySQL trigger to update a field to the value of id
I would like to have a trigger to perform following operation for inserted records:
# pseudocode
if new.group_id is null
set new.group_id = new.id
else
# don't touch it
end
More ...
10
votes
5answers
9k views
Can you access the auto increment value in MySQL within one statement?
I have a MySQL database which contains a table of users. The primary key of the table is 'userid', which is set to be an auto increment field.
What I'd like to do is when I insert a new user into ...
8
votes
5answers
5k views
prevent autoincrement on MYSQL duplicate insert
using mysql 5.1.49
i'm trying to implement a tagging system
the problem I have is with a table with two columns -- INNODB - id(autoincrement), tag(unique varchar)
when doing INSERT IGNORE INTO ...
3
votes
3answers
26k views
Escaping single quote in PHP when inserting into MySQL
I have a perplexing issue that I can't seem to comprehend... I'm hoping someone here might be able to point me in the right direction...
I have two SQL statements:
- the first enters information from ...
2
votes
3answers
5k views
Mysql insert into 2 tables
I want to make a insert into 2 tables
visits:
visit_id int | card_id int
registration:
registration_id int | type enum('in','out') | timestamp int | visit_id int
i want something like:
...
26
votes
7answers
9k views
Which is faster: multiple single INSERTs or one multiple-row INSERT?
I am trying to optimize one part of my code that inserts data into MySQL. Should I chain INSERTs to make one huge multiple-row INSERT or are multiple separate INSERTs faster?
4
votes
3answers
13k views
PHP mysql insert date format
Im using jQuery datepicker
the format of the datepicker is this 08/25/2012
i have errors when inserting to my database it insert only 0000-00-00 00 00 00
my codes is
<?php
$id = $_POST['id'];
...
4
votes
2answers
14k views
PHP/MySQL Insert null values
I'm struggling with some PHP/MySQL code. I am reading from 1 table, changing some fields then writing to another table, nothing happens if inserting and one of the array values is null when I would ...
12
votes
4answers
18k views
LAST_INSERT_ID() MySQL
I have a MySQL question that I think must be quite easy. I need to return the LAST INSERTED ID from table1 when I run the following MySql query:
INSERT INTO table1 (title,userid) VALUES ('test',1);
...
18
votes
6answers
30k views
MySQL - ignore insert error: duplicate entry
I am working in PHP.
Please what's the proper way of inserting new records into the DB, which has unique field.
I am inserting lot of records in a batch and I just want the new ones to be inserted ...
6
votes
4answers
939 views
How to get the id of a row i've just inserted php/mysql [duplicate]
Possible Duplicate:
PHP: how to get last inserted ID of a table?
I'm writing a function to add data do a database, but I then want to immediately use that entry in my code.
I know I could ...
2
votes
1answer
224 views
trying to insert different result sets by using single insert statement by checking condition
i have a winform with four textboxes and two dropdown lists and a Save button
textboxes are like these
Startdate textbox with value entered in the textbox 2011-03-02
(yyyy-mm-dd)
Enddate ...