0

我坚持要获取 mysql 最后一个增量 id :( 我刚刚尝试了 mysql_insert_id 但得到 0 而不是最后一个增量 id :( 这是数组和插入函数调用

$input_data = array(
                        'id' => '',
                        'booking_date' => $_POST['booking_date'],
                        'event_name' =>  $_POST['ev_name'],
                        'exb_comp_name' => $_POST['exb_comp_name'],
                        'address' =>  $_POST['address'],
                        'city' => $_POST['city'],
                        'country' => $_POST['country'],
                        'tel1' => $_POST['tel1'],
                        'tel2' => $_POST['tel2'],
                        'email' =>  $_POST['email'],
                        'package' =>  $_POST['package'],
                        'stand_no' => $_POST['stand_no'],
                        'hall_no' =>  $_POST['hall_no'],
                        'area' =>  $_POST['area'],
                        'contact_per' =>  $_POST['contact_per'],
                        'desg' => $_POST['desg'],
                        'cell_no' =>  $_POST['cell_no'],
                        'url' =>  $_POST['url'],
                      );
                      echo get_insert_id('exb_reg',$input_data);

这是功能代码

function get_insert_id($table_name, $data){
global $connection;
$value_a = '';
$value_b = '';

foreach($data as $field => $values){
    $value_a .= "`".$field."`,";
    $value_b .= "'".$values."',";
}
$value_a = substr($value_a, 0, strlen($value_a)-1);
$value_b = substr($value_b, 0, strlen($value_b)-1);
$query = "INSERT INTO `$table_name` ($value_a) VALUES ($value_b)";

$result = mysqli_query($connection,$query);

 $id = mysql_insert_id();  
return $id;

}

我在函数中尝试了回显,但最终结果为 0 :(

4

1 回答 1

4

您已经切换了数据库库。始终使用,它与已弃用的库mysqli_不兼容。mysql_

于 2014-04-14T06:49:44.933 回答