mysql-insert-id

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement'

心已入冬 提交于 2020-07-31 05:56:29
问题 When I run the following code, I get the error saying Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No index used in query/prepared statement' $mysql = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database'); if (mysqli_connect_errno()) { printf("DB error: %s", mysqli_connect_error()); exit(); } $get_emp_list = $mysql->prepare("SELECT id, name FROM calc"); if(!$get_emp_list){ echo "prepare failed\n"; echo "error: ",

Best way to find the last inserted ID in mysql using php

这一生的挚爱 提交于 2020-01-01 05:31:08
问题 Im wondering as to what the best solution is to get the last inserted ID after a mysql inquiry? I have found the following solutions : <?php function get_current_insert_id($table) { $q = "SELECT LAST_INSERT_ID() FROM $table"; return mysql_num_rows(mysql_query($q)) + 1; } ?> or even using mysql_insert_id php function, but apparently this function will not work well with bigint (thats what I am using for ID field) and if there are alot of consecutive sql inquiries it could be unreliable. Could

Can't get mysql_insert_id() to work

…衆ロ難τιáo~ 提交于 2019-12-31 05:16:16
问题 I tried this: $cid = mysql_insert_id($this->result); $this->result = "<div class='alert alert-success'>" . sprintf(_('Successfully added user id <b>%s</b> to the database.'), $cid) . "</div>"; but I only get this error: Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in This is the entire function (i added this $cid = mysql_insert_id($this->result); hoping to retrieve the id of the inserted data): private function adduser() { if (!empty($this->error)) return

MySQL foreign key relations vs mysql_insert_id to relate tables

☆樱花仙子☆ 提交于 2019-12-25 05:19:10
问题 This is for a sort of proof of concept draft to get things working, but don't want to have completely crap code. For my database, I tried to get true foreign key relations going using innoDB, but couldn't get it. Instead of using foreign keys, I decided to just pull mysql_insert_id() after inserts, saving it as a variable, then putting that variable into the related table. Is this horrible? Everything seems to work well, and I'm able to connect and relate ID's as needed. What benefits would

What happens if mysql_insert_id called form different places and different browsers at the same time?

六月ゝ 毕业季﹏ 提交于 2019-12-24 10:22:40
问题 Maybe i have some stupid questions about mysql_insert_id... I need to get the last inserted Id of a query using mysql_insert_id after mysql_query("INSERT INTO"). mysql_insert_id retrieves the generated Id by the previous query, but my question is... One php file called test.php with the following code mysql_query("INSERT INTO table (FirstName, LastName) VALUES ('" . $_POST['FirstName'] . "', '" . $_POST['LastName'] . "'); ") $lastId = mysql_insert_id(); ...continues some code using $lastId

PHP mysql_insert_id() for MySQL UUID() primary keys?

白昼怎懂夜的黑 提交于 2019-12-23 05:38:10
问题 Is there some equivalent to PHP mysql_insert_id to fetch the last inserted UUID() primary key? (I always get 0. It works for auto_inc integers though) 回答1: No, last_insert_id() only retrieves that last generated auto_increment fields. You'll have to do a select uuid() first, then do an insert using that uuid. However, note that uuids can't be guaranteed to be unique - they're simply very unlikely to collide. If you do require uniqueness, then go with an auto_increment - they'll never be re

mysql_insert_id, does not return the last inserted id when i place it in a function

放肆的年华 提交于 2019-12-23 02:32:56
问题 mysql_insert_id does not return the last inserted id when i place it inside a function. im kinda confused why it does not. here is my code: function addAlbum($artist,$album,$year,$genre) { $connection = mysql_connect(HOST,USER,PASS); $sql = 'INSERT INTO `'.TABLE_ARTIST.'` (artistName) VALUES ("'.$artist.'")'; $resultArtist = mysql_query($sql); $sql = 'INSERT INTO `'.TABLE_ALBUMS.'` (albumName) VALUES ("'.$album.'")'; $resultAlbums = mysql_query($sql); $sql = 'INSERT INTO `'.TABLE_GENRE.'`

mysql_insert_id issue in concurrency data inserting

你。 提交于 2019-12-17 17:01:12
问题 How reliable is mysql_insert_id() in a competitive condition? I mean when multiple users are inserting data at the same time, will this function return the true ID or it will return other user's inserted data ID? The table engine is MyISAM. 回答1: mysql_insert_id is completely multi-user safe.It is entirely relies upon the database connection, and you can only have one user per connection....So, as per your question, it returns true id.... From MySql documentation, The ID that was generated is