mysql-insert-id

How bad is using SELECT MAX(id) in MYSQL instead of mysql_insert_id() in PHP?

余生长醉 提交于 2019-11-30 01:40:18
问题 Background: I'm working on a system where the developers seem to be using a function which executes a MYSQL query like "SELECT MAX(id) AS id FROM TABLE" whenever they need to get the id of the LAST inserted row (the table having an auto_increment column). I know this is a horrible practice (because concurrent requests will mess the records), and I'm trying to communicate that to the non-tech / management team, to which their response is... "Oh okay, we'll only face this problem when we have

mysql_insert_id(); not returning value after successful row insert

孤者浪人 提交于 2019-11-28 04:23:05
问题 I swear I have poured and poured over every other similar question on this site and others... but I think I'm just missing something. Hopefully someone can point out a silly mistake that my brain is hiding from me. :) My script inserts values from a form into a table called "notes" At that point it creates two entries in a table called "relationships" through a function called newRelationship. The value of the variable "$note_id" is populated via my mysql_insert_id(); and passed into the

mysql_insert_id issue in concurrency data inserting

倖福魔咒の 提交于 2019-11-28 02:02:24
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. 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 maintained in the server on a per-connection basis. This means that the value returned by the function to a

getting mysql_insert_id() while using ON DUPLICATE KEY UPDATE with PHP

喜夏-厌秋 提交于 2019-11-27 19:05:18
I've found a few answers for this using mySQL alone, but I was hoping someone could show me a way to get the ID of the last inserted or updated row of a mysql DB when using PHP to handle the inserts/updates. Currently I have something like this, where column3 is a unique key, and there's also an id column that's an autoincremented primary key: $query ="INSERT INTO TABLE (column1, column2, column3) VALUES (value1, value2, value3) ON DUPLICATE KEY UPDATE SET column1=value1, column2=value2, column3=value3"; mysql_query($query); $my_id = mysql_insert_id(); $my_id is correct on INSERT, but

Get insert_id for all rows inserted in single mysqli query (multiple values)

自闭症网瘾萝莉.ら 提交于 2019-11-27 06:28:21
问题 Working in PHP and using MYSQLI. Trying to get the insert_id for all rows inserted from a single insert query with multiple values. Keeping it in a single call for efficiency. My actual code has hundreds of values in one insert query. However, here is some sample code for an insert with just 4 values: $sql = "INSERT INTO link_tags ( string_names_id, urls_id ) VALUES ( '2', '17' ), ( '8', '31' ), ( '8', '1' ), ( '8', '4' )"; $mysqli->query($sql); echo "id's: " .$mysqli->insert_id; The above

mysql_insert_id() returns 0

前提是你 提交于 2019-11-27 05:11:31
I know there are a lot of topics with the same title. But mostly it's the query that's been inserted in the wrong place. But I think I placed it right. So the problem is, that I still get 0 even when the data is inserted in the db. Does someone knows an answer where I could be wrong? here's my code: mysql_query('SET NAMES utf8'); $this->arr_kolommen = $arr_kolommen; $this->arr_waardes = $arr_waardes; $this->tabel = $tabel; $aantal = count($this->arr_kolommen); //$sql="INSERT INTO `tbl_photo_lijst_zoekcriteria` ( `PLZ_FOTO` , `PLZ_ZOEKCRITERIA`,`PLZ_CATEGORIE`)VALUES ('$foto', '$zoekje','

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

血红的双手。 提交于 2019-11-26 21:06:01
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: ", $mysql->error, "\n"; return; } $get_emp_list->execute(); $get_emp_list->bind_result($id, $emp_list);

mysql_insert_id() returns 0

我与影子孤独终老i 提交于 2019-11-26 11:26:37
问题 I know there are a lot of topics with the same title. But mostly it\'s the query that\'s been inserted in the wrong place. But I think I placed it right. So the problem is, that I still get 0 even when the data is inserted in the db. Does someone knows an answer where I could be wrong? here\'s my code: mysql_query(\'SET NAMES utf8\'); $this->arr_kolommen = $arr_kolommen; $this->arr_waardes = $arr_waardes; $this->tabel = $tabel; $aantal = count($this->arr_kolommen); //$sql=\"INSERT INTO `tbl