本文整理匯總了PHP中mysqli_insert_id函數的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli_insert_id函數的具體用法?PHP mysqli_insert_id怎麽用?PHP mysqli_insert_id使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mysqli_insert_id函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: processQuery
public function processQuery($sql, $type = NULL)
{
$result = mysqli_query($this->db, $sql);
$this->checkForError();
$data = array();
if ($result instanceof mysqli_result) {
$resultType = MYSQLI_NUM;
if ($type == 'assoc') {
$resultType = MYSQLI_ASSOC;
}
while ($row = mysqli_fetch_array($result, $resultType)) {
if (mysqli_affected_rows($this->db) > 1) {
array_push($data, $row);
} else {
$data = $row;
}
}
mysqli_free_result($result);
} else {
if ($result) {
$data = mysqli_insert_id($this->db);
}
}
return $data;
}
示例2: saveSubrutina
function saveSubrutina($idSubRutina, $Orden, $idRutina, $Nombre)
{
// Esta función nos regresa la subrutina de una rutina especifica (dividida por días)
//Creamos la conexión con la función anterior
$conexion = obtenerConexion();
if ($conexion) {
//Verificamos que la conexión se haya realizado de manera correcta
mysqli_set_charset($conexion, "utf8");
//formato de datos utf8
if ($idSubRutina == NULL or $idSubRutina == 0 or $idSubRutina == '') {
$sql = "INSERT INTO `Subrutina` (`Orden`, `IdRutina`, `Nombre`) VALUES ('{$Orden}', '{$idRutina}', '{$Nombre}');";
} else {
$sql = "UPDATE `Subrutina` SET `Orden`='{$Orden}', `IdRutina`='{$idRutina}', `Nombre`='{$Nombre}' WHERE `SR_ID`='{$idSubRutina}';";
}
if ($result = mysqli_query($conexion, $sql)) {
if ($idSubRutina == NULL or $idSubRutina == 0 or $idSubRutina == '') {
$idSubRutina = mysqli_insert_id($conexion);
}
$response["subrutina"] = $this->getsubrutinaByIdSubutina($idSubRutina);
$response["success"] = 0;
$response["message"] = 'Subrutina guardada correctamente';
} else {
$response["success"] = 4;
$response["message"] = 'Se presentó un error al ejecutar la consulta';
}
desconectar($conexion);
//desconectamos la base de datos
} else {
$response["success"] = 3;
$response["message"] = 'Se presentó un error al realizar la conexión con la base de datos';
}
return $response;
//devolvemos el array
}
示例3: venda
function venda($conn, $idUsuario, $idCliente)
{
$data = date('Y-m-d h:m:s');
$statusVenda = '1';
/*
statusVenda (0) = cancelada
statusVenda (1) = aberda
statusVenda (2) = concluida
*/
$sqlVenda = "SELECT * FROM venda WHERE id_usuario='{$idUsuario}' AND id_cliente='{$idCliente}'";
//
$sVenda = mysqli_query($conn, $sqlVenda);
if (!mysqli_num_rows($sVenda)) {
/* Verificando a existencia dessa venda, relacao funcionario cliente */
$insert_pedido = "INSERT INTO venda (id_usuario, data, id_cliente, statusVenda) VALUE\n ('{$idUsuario}', '{$data}', '{$idCliente}', '{$statusVenda}')";
mysqli_query($conn, $insert_pedido);
$idVenda = mysqli_insert_id($conn);
/* ID referente a esta venda */
} else {
/* --- Encontrar o id relacionado a essa venda */
$sql = "SELECT idVenda FROM venda WHERE id_cliente='{$idCliente}' AND id_usuario='{$idUsuario}'";
$query = mysqli_query($conn, $sql);
$getId = mysqli_fetch_array($query);
$idVenda = $getId['idVenda'];
}
return $idVenda;
}
示例4: queryToArray
public static function queryToArray($sql)
{
global $my_user, $my_pass, $my_host, $my_db, $config_enable_cache;
$link = Database::getLink();
$db_selected = mysqli_select_db($link, $my_db);
if (!$db_selected) {
die('Can\'t use ' . $my_db . ' : ' . mysqli_error($link));
}
// Perform Query
$result = mysqli_query($link, $sql);
$id = mysqli_insert_id($link);
if ($id > 0) {
// we did an insert, just return the id
return $id;
}
//echo ("\ndatabase qtoa before proc id is $id");
if (!$result) {
$message = 'Invalid query: ' . mysqli_error($link) . "\n";
$message .= 'Whole query: ' . $sql;
die($message);
}
if ($result === true) {
// probably an insert..
return false;
}
$rows = array();
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
示例5: read_hotels2
function read_hotels2()
{
global $db;
$gohar_hotel = array();
$safar_hotel = array();
$new_hotel = array();
$sql = mysqli_query($this->db_gohar, "SELECT `id`,`fa_hotel`,`en_hotel`,`stars` FROM `htl_hotel` ");
while ($row = mysqli_fetch_assoc($sql)) {
$gohar_hotel[$row['id']]['name'] = $row['fa_hotel'];
$gohar_hotel[$row['id']]['en_name'] = $row['en_hotel'];
$gohar_hotel[$row['id']]['stars'] = $row['stars'];
}
echo 'HOTELS COUNT :: ' . count($gohar_hotel) . '<br>';
foreach ($gohar_hotel as $id => $hotel) {
//$insert-> execute(array(':name'=>$hotel['name'],':en_name'=>$hotel['en_name'],':star'=>$hotel['stars']));
$sql = "INSERT INTO `hotels` (`id`, `name`, `en_name`, `star`) VALUES (NULL,'{$hotel['name']}','{$hotel['en_name']}','{$hotel['stars']}');)";
echo $sql . '<br>';
mysqli_query($db, $sql);
$hotels_id = mysqli_insert_id($db);
$sql = "INSERT INTO hotels_source (`hotels_id`,`source_id`,`name`,`en_name`,`id_source_hotel`) VALUES({$hotels_id},1,'{$hotel['name']}','{$hotel['en_name']}',{$id})";
echo '<br>' . $sql . '<br>';
mysqli_query($db, $sql);
echo $hotels_id . '<br>';
// echo $insert2->execute(array(':hotels_id'=>$hotels_id,':name'=>$hotel['name'],':en_name'=>$hotel['en_name'],':id_source_hotel'=>$id));
}
}
示例6: storeUser
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $gcm_regid)
{
// insert user into database
$c = new DB_Connect();
$d = $c->connect();
$test = mysqli_query($d, "SELECT * class_details where code='{$email}'");
if ($test) {
$result = mysqli_query($d, "INSERT INTO gcm_users(name, email, gcm_regid, created_at) VALUES('{$name}', '{$email}', '{$gcm_regid}', NOW())");
// check for successful store
if ($result) {
// get user details
$id = mysqli_insert_id();
// last inserted id
$result = mysqli_query($d, "SELECT * FROM gcm_users WHERE id = {$id}") or die(mysql_error());
// return user details
if (mysqli_num_rows($result) > 0) {
return mysqli_fetch_array($result);
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
示例7: lisa
function lisa()
{
// siia on vaja funktsionaalsust (13. nädalal)
global $connection;
if (empty($_SESSION["user"])) {
header("Location: ?page=login");
} elseif ($_SESSION["roll"] != "admin") {
header("Location: ?page=loomad");
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST["nimi"] == "" || $_POST["puur"] == "") {
$errors[] = "Nimi või puur on täitmata!";
} elseif (upload("liik") == "") {
$errors[] = "Faili saatmine ebaõnnestus";
} else {
$nimi = mysqli_real_escape_string($connection, $_POST["nimi"]);
$puur = mysqli_real_escape_string($connection, $_POST["puur"]);
$liik = mysqli_real_escape_string($connection, upload("liik"));
$sql = "INSERT INTO ttilk__loomaaed(nimi, puur, liik) VALUES ('{$nimi}', '{$puur}', '{$liik}')";
$result = mysqli_query($connection, $sql);
if (mysqli_insert_id($connection)) {
header("Location: ?page=loomad");
} else {
header("Location: ?page=loomavorm");
}
}
}
}
include_once 'views/loomavorm.html';
}
示例8: update
function update($id, $name)
{
$query = "update category set name = '{$this->name}' where id = {$id}";
$result = mysqli_query(self::$conn, $query);
//echo $this->name."effected rows = ".$result;
return mysqli_insert_id(self::$conn);
}
示例9: create
public function create($content, Users $user)
{
$message = new Messages();
$valid = $message->setContent($content);
if ($valid === true) {
$valid = $message->setUser($user);
if ($valid === true) {
$content = mysqli_real_escape_string($this->database, $message->getContent());
$id_user = $message->getUser();
$query = "INSERT INTO messages (content, id_user) \n\t\t\t\t\tVALUES ('" . $content . "', '" . $id_user . "')";
$result = mysqli_query($this->database, $query);
if ($result) {
$id = mysqli_insert_id($this->database);
if ($id) {
return $this->findById($id);
} else {
return "Erreur serveur.";
}
} else {
return mysqli_error();
}
} else {
return $valid;
}
} else {
return $valid;
}
}
示例10: __construct
public function __construct($query, $parameters, $resource, $link)
{
$this->resource = $resource;
$this->affected_rows = mysqli_affected_rows($link);
$this->last_inserted_id = mysqli_insert_id($link);
parent::__construct($query, $parameters);
}
示例11: work
function work($file_name, $connect)
{
$topic = "myschool";
$reg_ids = "";
$title = $_POST['title'];
$time = date("Y-m-d , H:i:s");
$query = "INSERT INTO `images`(`title`, `image`, `time`) VALUES ('{$title}', '{$file_name}', '{$time}')";
$result = mysqli_query($connect, $query);
if ($result) {
$pid = mysqli_insert_id($connect);
$selectQuery = "SELECT * FROM `images` WHERE `sno` = '{$pid}'";
$selectResult = mysqli_query($connect, $selectQuery);
if ($selectResult) {
if ($row = mysqli_fetch_array($selectResult)) {
$message[] = array("result" => "success", "title" => $title, "image" => $file_name, "date" => $row['time']);
$messages = array('image' => $message);
// TODO uncomment send_push_notification() to send message to devices
//var_dump($messages);
echo "<br><br>" . json_encode($messages) . "<br><br><br> Add more images if you want.<br>";
send_push_notification($reg_ids, json_encode($messages), $topic);
}
}
} else {
echo "<br>Error";
}
}
示例12: add_bd
function add_bd($name, $description, $category, $select)
{
require "configSQL.php";
if ($category == "Transport") {
$cat = "1";
} else {
if ($category == "Food") {
$cat = "2";
} else {
$cat = "3";
}
}
//ajout de l'appli
$req = "INSERT INTO appli (name, description, category) VALUES ('" . $name . "','" . $description . "','" . $cat . "')";
if (mysqli_query($link, $req)) {
//récup de l'id appli
$idAppli = mysqli_insert_id($link);
//récup de l'id pays
$slct = "SELECT * FROM countries WHERE name='%s'";
$req2 = sprintf($slct, $select);
$res2 = mysqli_query($link, $req2) or die(utf8_encode("request error : ") . $req2);
$data = mysqli_fetch_array($res2, MYSQLI_ASSOC);
$idCountry = $data["id"];
//ajout dans table appli par pays
$req3 = "INSERT INTO applibycountry (idCountry, idAppli) VALUES ('" . $idCountry . "','" . $idAppli . "')";
if (mysqli_query($link, $req3)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
示例13: save
/**
* Save or update the item data in database
*/
function save()
{
$class = get_called_class();
$query = "INSERT INTO " . static::$tableName . " (" . implode(",", array_keys($this->columns)) . ") VALUES(";
$keys = array();
$values = array();
foreach ($this->columns as $key => $value) {
// $keys[":".$key] = $value;
$values["'" . $value . "'"] = $value;
}
$query .= implode(",", array_keys($values)) . ")";
if (!($stmt = $this->conn->prepare($query))) {
echo 'Error: ' . $this->conn->error;
return false;
// throw exception, die(), exit, whatever...
} else {
$result = $stmt->execute();
$stmt->close();
}
if ($result) {
//echo '1';
return mysqli_insert_id($this->conn);
} else {
// Failed to insert record
//echo '2';
return -1;
// return 'USER_CREATE_FAILED';
}
}
示例14: executeInsertQuery
function executeInsertQuery($link, $query)
{
if (!mysqli_query($link, $query)) {
echo "Row doesn't work: SQL ['{$query}']";
}
return mysqli_insert_id($link);
}
示例15: clone_table
function clone_table($controller_dblink, $storage_dblink, $table_details, $target_details)
{
# Setting the cloned table settings
$table_id = $table_details['id'];
unset($table_details['id'], $table_details['rows'], $table_details['size'], $table_details['partitions']);
$table_details['name'] = $target_details->name;
$table_details['alias'] = $target_details->alias;
$table_details['environment'] = $target_details->environment;
# Adding our cloned table settings
$columns = [];
foreach ($table_details as $key => $value) {
$columns[] = "`" . $key . "`='" . mysqli_escape_string($controller_dblink, $value) . "'";
}
$query = "\tINSERT INTO\n\t\t\t\t\t" . NQ_TABLE_SETTINGS_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t" . implode(',', $columns);
mysqli_sub_query($controller_dblink, $query);
$new_table_id = mysqli_insert_id($controller_dblink);
# Cloning the table structure
$query = "\tCREATE TABLE \n\t\t\t\t\t" . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_STRUCTURE_PREFIX . $table_details['app_id'] . '_' . $new_table_id . "`\n\t\t\t\tLIKE\n\t\t\t\t\t" . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_STRUCTURE_PREFIX . $table_details['app_id'] . '_' . $table_id . "`";
mysqli_sub_query($storage_dblink, $query);
# Copying table links based on table_id
$query = "\tINSERT INTO\n\t\t\t\t\t" . NQ_TABLE_LINKS_TABLE . "\n\t\t\t\t\t(\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`table_id`,\n\t\t\t\t\t\t`link_table_id`,\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`column`,\n\t\t\t\t\t\t`type`\n\t\t\t\t\t)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t" . $new_table_id . ",\n\t\t\t\t\t\t`link_table_id`,\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`column`,\n\t\t\t\t\t\t`type`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TABLE_LINKS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`table_id` = " . $table_id;
mysqli_sub_query($controller_dblink, $query);
# Copying table links based on link_table_id
$query = "\tINSERT INTO\n\t\t\t\t\t" . NQ_TABLE_LINKS_TABLE . "\n\t\t\t\t\t(\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`table_id`,\n\t\t\t\t\t\t`link_table_id`,\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`column`,\n\t\t\t\t\t\t`type`\n\t\t\t\t\t)\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`table_id`,\n\t\t\t\t\t\t" . $new_table_id . ",\n\t\t\t\t\t\t`name`,\n\t\t\t\t\t\t`column`,\n\t\t\t\t\t\t`type`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TABLE_LINKS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`link_table_id` = " . $table_id;
mysqli_sub_query($controller_dblink, $query);
# Returning the table data
return true;
}