Questions tagged [lastinsertid]

135 questions
1
vote
3 answers

Two inserts in PHP/MySQL using LAST_INSERT_ID() and rows from another table

I am working on an events calendar using PHP and MySQL (V5.1) where the admin would add an event, and then an attendance list for that event would be created as well. I have three tables: events, attendance and members. So far I can create the event…
1
vote
1 answer

How do I get the Last Insert Id from a JayData transaction?

Using JayData to insert a new object (record) into a Sqlite database, how do I query for the last insert id? I can do it like this but it seems inelegant: DB.Members.orderByDescending('member.Id').take(1).toArray(function(member){ …
Adam Casey
  • 949
  • 2
  • 8
  • 24
1
vote
1 answer

how to save last id inside class?

there is a way to save the $id inside the class so I can use it next time I run the function? so far I get the right $id inside the function after the query is executed, but when I re-run the function I get an uninitialised $id again. class ShortURL…
user2035693
  • 193
  • 2
  • 16
1
vote
2 answers

SQLite3 and last_insert_rowid

This is how I create my handle $this->_handle = new SQLite3($this->_dbname); This is how I make my db query (shortened): $stmt = $this->_handle->prepare($sql); // execute query $result = $stmt->execute(); // get all results while($row =…
testing
  • 19,681
  • 50
  • 236
  • 417
1
vote
3 answers

Using an insert id from first of three queries in php

I want to store the data from several curl calls to an initial table, but last insert id is inserting wrong info Query 1 inserts data into table table1 id name email valuereturn 1 val val@email.com 0 I then post data 3…
Val
  • 412
  • 4
  • 11
1
vote
1 answer

Issue with PDO lastinsertid

I am a beginner programmer and am making a pretty simple insert into database application. Here is my code: $hostname = 'localhost'; $username = '***********'; $password = '**********'; $conn = new PDO("mysql:host=$hostname;dbname=***********",…
Muhambi
  • 3,472
  • 6
  • 31
  • 55
1
vote
2 answers

Copy and mutiple insert into (mysql)?

My problem is very simple to explain but I don't success to find the right answer to it ! I have 3 tables in mysql, called tA, tB, tC. I have one entry A in tA, 2 entries B in tB and 3 entries C in tC with a hierarchical architecture like this: …
bastien
  • 209
  • 2
  • 14
1
vote
1 answer

How to find latest inserted row from db row in YII?

I have a table "backup_history" which store sites backup details in my database with the following fields: id site_id backup_file_name file_size by (cron/manual) datetime For the next backup, I need to find out recent last backup date n time of the…
Frank
  • 2,285
  • 7
  • 43
  • 68
0
votes
3 answers

How to select last inserted row by id?

that my problem: I have database table like that: id (AI) market_id 1 6 2 10 3 6 4 10 5 11 How to select last inserted market_id by id?
Donatas Veikutis
  • 974
  • 2
  • 15
  • 36
0
votes
1 answer

PDO Transaction rolling back when returning LastInsertID

I am having a strange problem which I don't understand. I have the following function which is supposed to return $asset_ID: function commit_purchase($asset_type_ID, $org_ID, $asset_desc, $asset_cost, $date, $org_to_member_ID, $asset_ID,…
Progger
  • 2,266
  • 4
  • 27
  • 51
0
votes
2 answers

Get last record in mysql

Using this php code: try{ $dbh = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass); $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); // INSERT CLEAN DATA INTO TABLE… $sth = $dbh->prepare(" INSERT INTO…
CodeTalk
  • 3,571
  • 16
  • 57
  • 92
0
votes
1 answer

Inserting array data using mysql insert id and if statements

Ok so whilst I have been working on my PHP and MySQL skills I am new to inserting data into multiple tables in one go. I have done some reading around the subject and I appreciate the basics and the importance of normalised data etc and as such the…
Burdie87
  • 123
  • 2
  • 14
0
votes
1 answer

Most efficient way to do Mysql Multi select (and insert if not exists)

I have 20 tables with 2 fields, id and name description Colors id name 1 black 2 blue ... Sizes id name 1 100 2 105 ... Now i have the main table with 21 fields Main table `shoes` id Colors Sizes style ... 1 2 24 11 I have a form…
Colas
  • 157
  • 1
  • 2
  • 12
0
votes
2 answers

Inserting tuple's elements to database

I have a tuple that i wanna store its elements, I'm trying to insert it as following and it gives the following error, what am i doing wrong ? records_to_be_inserted is the tuple that has 8 elements. with self.connection: cur =…
NotCamelCase
  • 1,073
  • 1
  • 10
  • 18
0
votes
1 answer

How to OUT from a stored procedure using LAST_INSERT_ID()

Mysql Version 14.14 Distrib 5.1.41 I have a stored procedure that I am trying to get compiled but an error keeps cropping up. My stored procedure prepares an insert statement, executes it, deallocates the prepared statment and then attempts to…
1 2 3
8 9