本文整理汇总了PHP中mysqli_stmt_insert_id函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt_insert_id函数的具体用法?PHP mysqli_stmt_insert_id怎么用?PHP mysqli_stmt_insert_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_stmt_insert_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: model_add
function model_add($nimetus, $kogus)
{
global $link;
$query = 'INSERT INTO kleemets_kaubad (Nimetus, Kogus) VALUES (?,?)';
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($stmt, 'si', $nimetus, $kogus);
mysqli_stmt_execute($stmt);
$id = mysqli_stmt_insert_id($stmt);
mysqli_stmt_close($stmt);
return $id;
}
示例2: model_user_add
function model_user_add($kasutajanimi, $parool)
{
global $l;
$hash = password_hash($parool, PASSWORD_DEFAULT);
$query = 'INSERT INTO kleemets_kasutajad (Kasutajanimi, Parool) VALUES (?, ?)';
$stmt = mysqli_prepare($l, $query);
mysqli_stmt_bind_param($stmt, 'ss', $kasutajanimi, $hash);
mysqli_stmt_execute($stmt);
$id = mysqli_stmt_insert_id($stmt);
mysqli_stmt_close($stmt);
return $id;
}
示例3: saveUser
/**
* @param $connection
* @param array $user
* @return bool
*/
function saveUser($connection, array &$user)
{
$query = 'INSERT IGNORE INTO users (name, email, hashed_password) VALUES (?, ?, ?)';
$statement = mysqli_prepare($connection, $query);
mysqli_stmt_bind_param($statement, 'sss', $user['name'], $user['email'], $user['hashed_password']);
mysqli_stmt_execute($statement);
$inserted = (bool) mysqli_stmt_affected_rows($statement);
if ($inserted) {
$user['id'] = mysqli_stmt_insert_id($statement);
}
mysqli_stmt_close($statement);
return $inserted;
}
示例4: saveItem
public function saveItem($dbc, $cid)
{
$query = "INSERT INTO basket(cartID,itemName,Value) VALUES(?,?,?)";
$stmt = mysqli_prepare($dbc, $query);
if (!$stmt) {
die('mysqli error: ' . mysqli_error($dbc));
}
mysqli_stmt_bind_param($stmt, "dsd", $cid, $this->name, $this->value);
if (!mysqli_execute($stmt)) {
die('stmt error: ' . mysqli_stmt_error($stmt));
}
$this->id = mysqli_stmt_insert_id($stmt);
}
示例5: model_user_add
function model_user_add($kasutajanimi, $parool)
{
global $l;
$hash = password_hash($parool, PASSWORD_DEFAULT);
$query = "INSERT INTO areinman__kasutajad (Kasutajanimi, Parool) VALUES (?,?)";
$stmt = mysqli_prepare($l, $query);
if (mysqli_error($l)) {
echo mysqli_error($l);
exit;
}
mysqli_stmt_bind_param($stmt, "ss", $kasutajanimi, $hash);
mysqli_execute($stmt);
$id = mysqli_stmt_insert_id($stmt);
mysqli_stmt_close($stmt);
return $id;
}
示例6: insertUser
public function insertUser($dbc)
{
require_once '../mysqli_connect.php';
//Insert info into the database
$query = "INSERT INTO users(firstName,lastName,email, password, streetAddress, postalCode, DOB, gender) VALUES (?,?,?,?,?,?,?,?)";
//Prepare mysqli statement
$stmt = mysqli_prepare($dbc, $query);
if (!$stmt) {
die('mysqli error1: ' . mysqli_error($dbc));
}
//Bind parameters
mysqli_stmt_bind_param($stmt, "ssssssds", $this->firstName, $this->lastName, $this->email, $this->password, $this->streetAddress, $this->postalCode, $this->DOB, $this->gender);
if (!mysqli_execute($stmt)) {
die('stmt error2: ' . mysqli_stmt_error($stmt));
}
$this->id = mysqli_stmt_insert_id($stmt);
}
示例7: executeNonQuery
public function executeNonQuery($sql, $argv = NULL)
{
//Logger::trace("MysqlDao.executeNonQuery executed", LOG_LEVEL_NOTICE);
$affected = 0;
// 校验参数有效性
$lowstr = strtolower($sql);
if (strtolower(substr($lowstr, 0, 6)) === "select") {
echo "Invalid query SQL statement.";
}
//echo $sql;
// 创建数据库连接(如果需要)
$connected = $this->connected();
$conn = $connected ? $this->conn : $this->connect(FALSE);
// 将默认字符集设置为utf8
mysqli_query($conn, "set names 'utf8'");
mysqli_query($conn, "set character set 'utf8'");
// 执行SQL语句
$stmt = mysqli_prepare($conn, $sql);
if (mysqli_errno($conn)) {
$errno = mysqli_errno($conn);
$error = "MYSQL ERROR #" . $errno . " : " . mysqli_error($conn);
echo $error;
}
// 根据参数的个数动态生成参数绑定语句
if (isset($argv) && count($argv) > 0) {
$bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, ";
$paramstr = "";
$bindstr = "";
$holdstr = "";
$i = 0;
foreach ($argv as $arg) {
$paramstr .= "\$invar{$i}, ";
$bindstr .= "\$invar{$i} = \$argv[{$i}]; ";
$holdstr .= "s";
$i++;
}
$bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, \"{$holdstr}\", " . substr($paramstr, 0, strlen($paramstr) - 2) . "); ";
$bind_param_cmd .= $bindstr;
eval($bind_param_cmd);
//将字符串中的变量代入
}
// 执行SQL语句
mysqli_stmt_execute($stmt);
if (mysqli_stmt_errno($stmt)) {
$errno = mysqli_stmt_errno($stmt);
$error = "MYSQL ERROR #" . $errno . " : " . mysqli_stmt_error($stmt);
echo $error;
}
$this->insert_id = mysqli_stmt_insert_id($stmt);
//数据库操作数据id
//echo $this->insert_id;
$affected = mysqli_stmt_affected_rows($stmt);
mysqli_stmt_close($stmt);
// 关闭数据库连接(如果需要)
if (!$connected) {
$this->disconnect($conn);
}
return $affected;
}
示例8: createTraceInTimeline
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function createTraceInTimeline($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (idTimeline, idTrace, idSelector, position, delay, visible) VALUES (?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'iiiiii', $item->idTimeline, $item->idTrace, $item->idSelector, $item->position, $item->delay, $item->visible);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
示例9: printf
printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_stmt_close($stmt);
// no auto_increment column
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, "INSERT INTO test_mysqli_stmt_insert_id_table_1(id, label) VALUES (100, 'a')") || !mysqli_stmt_execute($stmt)) {
printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (0 !== ($tmp = mysqli_stmt_insert_id($stmt))) {
printf("[007] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
}
if (mysqli_get_server_version($link) > 50000 && (!mysqli_stmt_prepare($stmt, "ALTER TABLE test_mysqli_stmt_insert_id_table_1 MODIFY id INT NOT NULL AUTO_INCREMENT") || !mysqli_stmt_execute($stmt))) {
printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
} else {
if (mysqli_get_server_version($link) < 50000) {
mysqli_query($link, "ALTER TABLE test_mysqli_stmt_insert_id_table_1 MODIFY id INT NOT NULL AUTO_INCREMENT");
}
}
if (!mysqli_stmt_prepare($stmt, "INSERT INTO test_mysqli_stmt_insert_id_table_1(label) VALUES ('a')") || !mysqli_stmt_execute($stmt)) {
printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (0 === ($tmp = mysqli_stmt_insert_id($stmt))) {
printf("[010] Expecting int/any non zero, got %s/%s\n", gettype($tmp), $tmp);
}
mysqli_stmt_close($stmt);
mysqli_close($link);
var_dump(mysqli_stmt_insert_id($stmt));
print "done!";
error_reporting(0);
$test_table_name = 'test_mysqli_stmt_insert_id_table_1';
require_once "clean_table.inc";
示例10: executeNonQuery
public function executeNonQuery($sql, $argv = NULL)
{
//Logger::trace("MysqlDao.executeNonQuery executed", LOG_LEVEL_NOTICE);
$affected = 0;
$lowstr = strtolower($sql);
if (strtolower(substr($lowstr, 0, 6)) === "select") {
//Logger::trace("Invalid query SQL statement.", LOG_LEVEL_ERROR);
//Logger::debug("sql = $sql, argv = $argv");
throw new DaoException("Invalid query SQL statement.");
}
$connected = $this->connected();
$conn = $connected ? $this->conn : $this->connect(FALSE);
mysqli_query($conn, "set names 'utf8'");
$stmt = mysqli_prepare($conn, $sql);
if (mysqli_errno($conn)) {
$errno = mysqli_errno($conn);
$error = "MYSQL ERROR #" . $errno . " : " . mysqli_error($conn);
//Logger::trace($error, LOG_LEVEL_ERROR);
//Logger::debug("sql = $sql ". ($argv));
throw new DaoException("database error---", $errno);
}
//Logger::trace("sql = " . $sql, LOG_LEVEL_VERBOSE);
if (isset($argv) && count($argv) > 0) {
$bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, ";
$paramstr = "";
$bindstr = "";
$holdstr = "";
$i = 0;
foreach ($argv as $arg) {
$paramstr .= "\$invar{$i}, ";
$bindstr .= "\$invar{$i} = \$argv[{$i}]; ";
$holdstr .= "s";
$i++;
}
$bind_param_cmd = "mysqli_stmt_bind_param(\$stmt, \"{$holdstr}\", " . substr($paramstr, 0, strlen($paramstr) - 2) . "); ";
$bind_param_cmd .= $bindstr;
//Logger::trace("bind parameter: " . $bind_param_cmd, LOG_LEVEL_VERBOSE);
eval($bind_param_cmd);
}
mysqli_stmt_execute($stmt);
if (mysqli_stmt_errno($stmt)) {
$errno = mysqli_stmt_errno($stmt);
$error = "MYSQL ERROR #" . $errno . " : " . mysqli_stmt_error($stmt);
//Logger::trace($error, LOG_LEVEL_ERROR);
//Logger::debug("sql = $sql ". ($argv));
throw new DaoException("database error...", $errno);
}
$this->insert_id = mysqli_stmt_insert_id($stmt);
$affected = mysqli_stmt_affected_rows($stmt);
mysqli_stmt_close($stmt);
if (!$connected) {
$this->disconnect($conn);
}
return $affected;
}
示例11: printf
if (!$stmt->prepare("INSERT INTO test_mysqli_class_mysqli_stmt_interface_table_1(id, label) VALUES (100, 'z')") || !$stmt->execute()) {
printf("[001] [%d] %s\n", $stmt->errno, $stmt->error);
}
assert(mysqli_stmt_affected_rows($stmt) === $stmt->affected_rows);
printf("stmt->affected_rows = '%s'\n", $stmt->affected_rows);
assert(mysqli_stmt_errno($stmt) === $stmt->errno);
printf("stmt->errno = '%s'\n", $stmt->errno);
assert(mysqli_stmt_error($stmt) === $stmt->error);
printf("stmt->error = '%s'\n", $stmt->error);
assert(mysqli_stmt_error_list($stmt) === $stmt->error_list);
var_dump("stmt->error = ", $stmt->error_list);
assert(mysqli_stmt_field_count($stmt) === $stmt->field_count);
printf("stmt->field_count = '%s'\n", $stmt->field_count);
assert($stmt->id > 0);
printf("stmt->id = '%s'\n", $stmt->id);
assert(mysqli_stmt_insert_id($stmt) === $stmt->insert_id);
printf("stmt->insert_id = '%s'\n", $stmt->insert_id);
assert(mysqli_stmt_num_rows($stmt) === $stmt->num_rows);
printf("stmt->num_rows = '%s'\n", $stmt->num_rows);
assert(mysqli_stmt_param_count($stmt) === $stmt->param_count);
printf("stmt->param_count = '%s'\n", $stmt->param_count);
assert(mysqli_stmt_sqlstate($stmt) === $stmt->sqlstate);
printf("stmt->sqlstate = '%s'\n", $stmt->sqlstate);
printf("\nAccess to undefined properties:\n");
printf("stmt->unknown = '%s'\n", @$stmt->unknown);
@($stmt->unknown = 13);
printf("stmt->unknown = '%s'\n", @$stmt->unknown);
printf("\nPrepare using the constructor:\n");
$stmt = new mysqli_stmt($link, 'SELECT id FROM test_mysqli_class_mysqli_stmt_interface_table_1 ORDER BY id');
if (!$stmt->execute()) {
printf("[002] [%d] %s\n", $stmt->errno, $stmt->error);
示例12: printf
mysqlnd resets the IDE to 0
libmysql doesn't
$link->change_user ($user, $passwd, $db);
if (0 != $link->insert_id || 0 != mysqli_insert_id($link)) {
printf("[007] mysqli_change_user changes insert_id: %s", var_export($link->insert_id, true));
die();
}
*/
$stmt = $link->prepare("SELECT 1");
if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
printf("[008a] mysqli_prepare changes insert_id: %s", var_export($link->insert_id, true));
die;
}
echo mysqli_error($link);
if (0 != $stmt->insert_id || 0 != mysqli_stmt_insert_id($stmt)) {
printf("[008b] mysqli_stmt doesn't initialise insert_id: %s", var_export($stmt->insert_id, true));
die;
}
unset($stmt);
if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
printf("[009] stmt free changes insert_id: %s", var_export($link->insert_id, true));
die;
}
$link->query("DROP TABLE IF EXISTS test_insert_id_var");
echo "DONE";
require_once "connect.inc";
if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_insert_id_var")) {
示例13: insert
function insert($query, $inputArray, $id = "", $close = 0)
{
$this->Open();
if (!$this->conn) {
$this->message = 'Ingen forbindelse til databasen. Pr�v igjen senere.';
return false;
} else {
$inputArray = $this->_getInputArrayType($inputArray);
// GJ�RE KLAR FOR INSERT
if ($stmt = mysqli_prepare($this->conn, $query)) {
/* OPPRETTER ET ARRAY, BINDROW, MED ARGUMENTENE TIL BIND PARAM (1. ER STATEMENT, 2. ER STRINGEN
MED TYPENE OG RESTEN ER ALLE VARIABLENE TIL QUERYET)*/
$bindRow[0] = $stmt;
$bindRow[1] = "";
foreach ($inputArray as $entry) {
$bindRow[] =& $entry[0];
$bindRow[1] .= $entry[1];
}
// BINDE PARAMTERNE
call_user_func_array("mysqli_stmt_bind_param", $this->refValues($bindRow));
$res = mysqli_stmt_execute($stmt);
if ($close) {
$this->close();
}
// KJ�RE QUERYET
if (!$res) {
return false;
}
if ($id > 0) {
return $id;
} else {
if ($id == -1) {
return $res;
} else {
return mysqli_stmt_insert_id($stmt);
}
}
} else {
echo "Query feilet: <br>Connection: \"{$connection}\"<br>";
echo mysqli_error($this->conn) . "<br>Query:<br>";
echo $query . "<br>";
}
if ($close) {
echo mysqli_error($this->conn);
}
return false;
}
}
示例14: createTimeline
/**
* Returns the item corresponding to the value specified for the primary key.
*
* Add authorization or any logical checks for secure access to your data
*
*
* @return stdClass
*/
public function createTimeline($item) {
$stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (title, description, zoomStart, zoomEnd, position) VALUES (?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'ssiii', $item->title, $item->description, $item->zoomStart, $item->zoomEnd, $item->position);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
示例15: add
/**
* 添加一笔数据,对应INSERT 。对已被执行过字段赋值的本对象,执行插入数据表的操作。
* @return boolean 成功为true,失败为false
*/
public function add()
{
$rt = false;
$fields = null;
$values = null;
$types = null;
$params = [];
foreach ($this->fields as $k => $v) {
if ($k !== $this->AIField && $v['value'] != null) {
$fields .= "`{$k}`,";
$values .= "?,";
$types .= $v['type'];
$params[] =& $this->fields[$k]['value'];
}
}
$fields = trim($fields, ",");
$values = trim($values, ",");
$sql = "insert into `{$this->tableName}` ({$fields}) values ({$values})";
$this->lastSql = $sql;
$stmt = mysqli_prepare($this->conn, $sql);
if ($stmt) {
call_user_func_array([$stmt, "bind_param"], array_merge([$types], $params));
if (mysqli_stmt_execute($stmt)) {
if (strlen($this->AIField) > 0) {
$this->fields[$this->AIField]["value"] = mysqli_stmt_insert_id($stmt);
}
$rt = $this->fields[$this->AIField]["value"];
} else {
$this->logError(mysqli_stmt_error($stmt));
}
mysqli_stmt_close($stmt);
} else {
$this->logError(mysqli_error($this->conn));
}
$this->clear();
$this->degbugLog();
return $rt;
}