Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql to MariaDB mysql_insertid – LAST_INSERT_ID issue

My host recently switched from mysql to mariadb. Most everything transitioned well except the:

$id = $sth->{mysql_insertid};

This is a perl cgi.pm script. My code is:

my $dbh = DBI->connect("DBI:MariaDB:database=$database;host=localhost", $MYSQLuserid, $MYSQLpassword, { RaiseError => 1, PrintError => 0 });
my $sth = $dbh->prepare(qq(INSERT INTO mytable VALUES ($questionmarks) )) or die $DBI::errstr;
$sth->execute(@new_row) or die $DBI::errstr; #question marks and new_row were never the problem
$id = $sth->{mysql_insertid};  # <<<<<<<< culprit
$sth->finish() or die $DBI::errstr;

This is the error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

DBD::MariaDB::st FETCH failed: Unknown attribute mysql_insertid at my.cgi line 23234

If you can provide actual code that would be great. If auto increment needs to be changed, I will do that too. Any help is appreciated

I’ve tried these:

$id = $sth->{LAST_INSERT_ID};
$id = $sth=>LAST_INSERT_ID(mutable);
$id = mysqli_use_result($sth->$dbh);
$id =(LAST_INSERT_ID(), 1);
SELECT LAST_INSERT_ID();
$id = $sth->LAST_INSERT_ID();
$id = $sth->mysqli_insert_id();
$id = mysqli_insert_id();
SET @id = LAST_INSERT_ID();

>Solution :

You can use $sth->last_insert_id() or $dbh->last_insert_id()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading