PDO Prepared Inserts multiple rows in single query

Multiple Values Insert with PDO Prepared Statements Inserting multiple values in one execute statement. Why because according to this page it is faster than regular inserts. $datafields = array(‘fielda’, ‘fieldb’, … ); $data[] = array(‘fielda’ => ‘value’, ‘fieldb’ => ‘value’ ….); $data[] = array(‘fielda’ => ‘value’, ‘fieldb’ => ‘value’ ….); more data values or you … Read more

LAST_INSERT_ID() MySQL

You could store the last insert id in a variable : INSERT INTO table1 (title,userid) VALUES (‘test’, 1); SET @last_id_in_table1 = LAST_INSERT_ID(); INSERT INTO table2 (parentid,otherid,userid) VALUES (@last_id_in_table1, 4, 1); Or get the max id from table1 (EDIT: Warning. See note in comments from Rob Starling about possible errors from race conditions when using the … Read more

Add new row to dataframe, at specific row-index, not appended?

Here’s a solution that avoids the (often slow) rbind call: existingDF <- as.data.frame(matrix(seq(20),nrow=5,ncol=4)) r <- 3 newrow <- seq(4) insertRow <- function(existingDF, newrow, r) { existingDF[seq(r+1,nrow(existingDF)+1),] <- existingDF[seq(r,nrow(existingDF)),] existingDF[r,] <- newrow existingDF } > insertRow(existingDF, newrow, r) V1 V2 V3 V4 1 1 6 11 16 2 2 7 12 17 3 1 2 3 … Read more

SQL Server: Is it possible to insert into two tables at the same time?

In one statement: No. In one transaction: Yes BEGIN TRANSACTION DECLARE @DataID int; INSERT INTO DataTable (Column1 …) VALUES (….); SELECT @DataID = scope_identity(); INSERT INTO LinkTable VALUES (@ObjectID, @DataID); COMMIT The good news is that the above code is also guaranteed to be atomic, and can be sent to the server from a client … Read more

Increment a database field by 1

Updating an entry: A simple increment should do the trick. UPDATE mytable SET logins = logins + 1 WHERE id = 12 Insert new row, or Update if already present: If you would like to update a previously existing row, or insert it if it doesn’t already exist, you can use the REPLACE syntax or … Read more

How to insert a row in an HTML table body in JavaScript

If you want to add a row into the tbody, get a reference to it and call its insertRow method. var tbodyRef = document.getElementById(‘myTable’).getElementsByTagName(‘tbody’)[0]; // Insert a row at the end of table var newRow = tbodyRef.insertRow(); // Insert a cell at the end of the row var newCell = newRow.insertCell(); // Append a text … Read more

postgresql: INSERT INTO … (SELECT * …)

As Henrik wrote you can use dblink to connect remote database and fetch result. For example: psql dbtest CREATE TABLE tblB (id serial, time integer); INSERT INTO tblB (time) VALUES (5000), (2000); psql postgres CREATE TABLE tblA (id serial, time integer); INSERT INTO tblA SELECT id, time FROM dblink(‘dbname=dbtest’, ‘SELECT id, time FROM tblB’) AS … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)