It seems that mysqli_insert_id is not working

I have been trying to make this work for several hours and cannot do anything. The code I am using is below. I am working on a phpbb page that explains template and sql query setup.

$sql_query = 'INSERT INTO ' . rosters . ' ' . $db->sql_build_array('INSERT', $sql_rost);
$result_rost = $db->sql_query($sql_query);

$roster_last = $mysqli->insert_id;

 $template->assign_block_vars('some_block', array(
    'ROSTER'    => $roster_last,
    'TEST' =>'test'
));
$db->sql_freeresult($result_rost);

      

The insert request works because I see a new record in the database, and on the template I used TEST to make sure that this block is displayed and what it is.

Also, I have not used

mysqli_insert_id($link) 

      

because I am connected to the database with a different piece of code, so I don't want to replicate the database connection. Without $link

I get an error that mysqli_insert_id

another parameter is expected.

+3


source to share


1 answer


I dont think you can use mysql to create a query and then use mysqli to get the id. Try the following:

$db->insert_id;

      

Edit: just noticed that you said you were working with phpbb. The phpbb wiki offers the following:



$db->sql_nextid();

      

Source: https://wiki.phpbb.com/Database_Abstraction_Layer

+2


source







All Articles