search

Home  >  Q&A  >  body text

If mysqli_query is encapsulated, is there any way to use mysqli_insert_id?

public static function mquery($sql){

$conn = self::db_connect();

$rs=mysqli_query($conn,$sql);

mysqli_close($conn);

public static function insert($table,$data){

$conn=self::db_connect();

$fields = array();

$values = array();

foreach ($data as $key => $value) {

$value = str_replace("'", '&apos', $value);//单引号替换字符实体

$value = str_replace('"', '"', $value);//双引号替换

$fields[]= "`".$key."`";

$values[]="'".$value."'";


}

$fields = implode(',', $fields);

$values = implode(',',$values);

//sql 语句

$sql = "insert into {$table} ({$fields}) values ({$values})";

//dump($sql);exit();

$insert_id =0;

if (mysqli_query( $conn,$sql)){

$insert_id = mysqli_insert_id($conn);

}

mysqli_close($conn);

return $insert_id;

}

return $rs;

}


星火星火2236 days ago1232

reply all(1)I'll reply

  • 星火

    星火2018-10-14 07:42:07

    If mysqli_query is replaced with self::mquery() mysqli_insert_id (what should be passed in here)

    reply
    0
  • Cancelreply