本文整理汇总了PHP中mysqli_stmt_error函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt_error函数的具体用法?PHP mysqli_stmt_error怎么用?PHP mysqli_stmt_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysqli_stmt_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mysqli_fetch_array_large
function mysqli_fetch_array_large($offset, $link, $package_size)
{
/* we are aiming for maximum compression to test MYSQLI_CLIENT_COMPRESS */
$random_char = str_repeat('a', 255);
$sql = "INSERT INTO test(label) VALUES ";
while (strlen($sql) < $package_size - 259) {
$sql .= sprintf("('%s'), ", $random_char);
}
$sql = substr($sql, 0, -2);
$len = strlen($sql);
assert($len < $package_size);
if (!@mysqli_query($link, $sql)) {
if (1153 == mysqli_errno($link) || 2006 == mysqli_errno($link) || stristr(mysqli_error($link), 'max_allowed_packet')) {
/*
myslqnd - [1153] Got a packet bigger than 'max_allowed_packet' bytes
libmysql -[2006] MySQL server has gone away
*/
return false;
}
printf("[%03d + 1] len = %d, [%d] %s\n", $offset, $len, mysqli_errno($link), mysqli_error($link));
return false;
}
/* buffered result set - let's hope we do not run into PHP memory limit... */
if (!($res = mysqli_query($link, "SELECT id, label FROM test"))) {
printf("[%03d + 2] len = %d, [%d] %s\n", $offset, $len, mysqli_errno($link), mysqli_error($link));
return false;
}
while ($row = mysqli_fetch_assoc($res)) {
if ($row['label'] != $random_char) {
printf("[%03d + 3] Wrong results - expecting '%s' got '%s', len = %d, [%d] %s\n", $offset, $random_char, $row['label'], $len, mysqli_errno($link), mysqli_error($link));
return false;
}
}
mysqli_free_result($res);
if (!($stmt = mysqli_prepare($link, "SELECT id, label FROM test"))) {
printf("[%03d + 4] len = %d, [%d] %s\n", $offset, $len, mysqli_errno($link), mysqli_error($link));
return false;
}
/* unbuffered result set */
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d + 5] len = %d, [%d] %s, [%d] %s\n", $offset, $len, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt), mysqli_errno($link), mysqli_error($link));
return false;
}
$id = $label = NULL;
if (!mysqli_stmt_bind_result($stmt, $id, $label)) {
printf("[%03d + 6] len = %d, [%d] %s, [%d] %s\n", $offset, $len, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt), mysqli_errno($link), mysqli_error($link));
return false;
}
while (mysqli_stmt_fetch($stmt)) {
if ($label != $random_char) {
printf("[%03d + 7] Wrong results - expecting '%s' got '%s', len = %d, [%d] %s\n", $offset, $random_char, $label, $len, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
}
mysqli_stmt_free_result($stmt);
mysqli_stmt_close($stmt);
return true;
}
示例2: bind_twice
function bind_twice($link, $engine, $sql_type1, $sql_type2, $bind_type1, $bind_type2, $bind_value1, $bind_value2, $offset)
{
if (!mysqli_query($link, "DROP TABLE IF EXISTS test_mysqli_stmt_bind_param_type_juggling_table_1")) {
printf("[%03d + 1] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
mysqli_autocommit($link, true);
$sql = sprintf("CREATE TABLE test_mysqli_stmt_bind_param_type_juggling_table_1(col1 %s, col2 %s) ENGINE=%s", $sql_type1, $sql_type2, $engine);
if (!mysqli_query($link, $sql)) {
printf("[%03d + 2] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!($stmt = mysqli_stmt_init($link))) {
printf("[%03d + 3] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!mysqli_stmt_prepare($stmt, "INSERT INTO test_mysqli_stmt_bind_param_type_juggling_table_1(col1, col2) VALUES (?, ?)")) {
printf("[%03d + 4] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_bind_param($stmt, $bind_type1 . $bind_type2, $bind_value1, $bind_value1)) {
printf("[%03d + 5] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d + 6] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_bind_param($stmt, $bind_type1 . $bind_type2, $bind_value1, $bind_value2)) {
printf("[%03d + 7] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d + 8] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
mysqli_stmt_close($stmt);
if (!($res = mysqli_query($link, "SELECT col1, col2 FROM test_mysqli_stmt_bind_param_type_juggling_table_1"))) {
printf("[%03d + 9] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if (2 !== ($tmp = mysqli_num_rows($res))) {
printf("[%03d + 10] Expecting 2 rows, got %d rows [%d] %s\n", $offset, $tmp, mysqli_errno($link), mysqli_error($link));
}
$row = mysqli_fetch_assoc($res);
if ($row['col1'] != $bind_value1 || $row['col2'] != $bind_value1) {
printf("[%03d + 11] Expecting col1 = %s, col2 = %s got col1 = %s, col2 = %s - [%d] %s\n", $offset, $bind_value1, $bind_value1, $row['col1'], $row['col2'], mysqli_errno($link), mysqli_error($link));
return false;
}
$row = mysqli_fetch_assoc($res);
if ($row['col1'] != $bind_value1 || $row['col2'] != $bind_value2) {
printf("[%03d + 12] Expecting col1 = %s, col2 = %s got col1 = %s, col2 = %s - [%d] %s\n", $offset, $bind_value1, $bind_value2, $row['col1'], $row['col2'], mysqli_errno($link), mysqli_error($link));
return false;
}
mysqli_free_result($res);
return true;
}
示例3: mysqli_update
function mysqli_update($db, $sql)
{
$stmt = call_user_func_array('mysqli_interpolate', func_get_args());
if (!mysqli_stmt_execute($stmt)) {
throw new mysqli_sql_exception(mysqli_stmt_error($stmt), mysqli_stmt_errno($stmt));
}
$affected = mysqli_stmt_affected_rows($stmt);
mysqli_stmt_close($stmt);
return (int) $affected;
}
示例4: test_format
function test_format($link, $format, $from, $order_by, $expected, $offset)
{
if (!($stmt = mysqli_stmt_init($link))) {
printf("[%03d] Cannot create PS, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if ($order_by) {
$sql = sprintf('SELECT %s AS _format FROM %s ORDER BY %s', $format, $from, $order_by);
} else {
$sql = sprintf('SELECT %s AS _format FROM %s', $format, $from);
}
if (!mysqli_stmt_prepare($stmt, $sql)) {
printf("[%03d] Cannot prepare PS, [%d] %s\n", $offset + 1, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d] Cannot execute PS, [%d] %s\n", $offset + 2, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_store_result($stmt)) {
printf("[%03d] Cannot store result set, [%d] %s\n", $offset + 3, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!is_array($expected)) {
$result = null;
if (!mysqli_stmt_bind_result($stmt, $result)) {
printf("[%03d] Cannot bind result, [%d] %s\n", $offset + 4, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_fetch($stmt)) {
printf("[%03d] Cannot fetch result,, [%d] %s\n", $offset + 5, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if ($result !== $expected) {
printf("[%03d] Expecting %s/%s got %s/%s with %s - %s.\n", $offset + 6, gettype($expected), $expected, gettype($result), $result, $format, $sql);
}
} else {
$order_by_col = $result = null;
if (!mysqli_stmt_bind_result($stmt, $order_by_col, $result)) {
printf("[%03d] Cannot bind result, [%d] %s\n", $offset + 7, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
reset($expected);
while ((list($k, $v) = each($expected)) && mysqli_stmt_fetch($stmt)) {
if ($result !== $v) {
printf("[%03d] Row %d - expecting %s/%s got %s/%s [%s] with %s - %s.\n", $offset + 8, $k, gettype($v), $v, gettype($result), $result, $order_by_col, $format, $sql);
}
}
}
mysqli_stmt_free_result($stmt);
mysqli_stmt_close($stmt);
return true;
}
示例5: 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);
}
示例6: mysqli_interpolate
function mysqli_interpolate($db, string $sql, ...$args) : mysqli_stmt
{
$argn = count($args);
$stmt = mysqli_prepare($db, $sql);
if ($stmt === false) {
throw new mysqli_sql_exception(mysqli_error($db), mysqli_errno($db));
}
if ($argn) {
$syms = str_repeat('s', $argn);
if (false === mysqli_stmt_bind_param($stmt, $syms, ...$args)) {
throw new mysqli_sql_exception(mysqli_stmt_error($stmt), mysqli_stmt_errno($stmt));
}
}
return $stmt;
}
示例7: 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);
}
示例8: zerofill
function zerofill($offset, $link, $datatype, $insert = 1)
{
mysqli_query($link, 'ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 DROP zero');
$sql = sprintf('ALTER TABLE test_mysqli_stmt_bind_result_zerofill_table_1 ADD zero %s UNSIGNED ZEROFILL', $datatype);
if (!mysqli_query($link, $sql)) {
// no worries - server might not support it
return true;
}
if (!mysqli_query($link, sprintf('UPDATE test_mysqli_stmt_bind_result_zerofill_table_1 SET zero = %s', $insert))) {
printf("[%03d] UPDATE failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!($stmt = mysqli_prepare($link, 'SELECT zero FROM test_mysqli_stmt_bind_result_zerofill_table_1 LIMIT 1'))) {
printf("[%03d] SELECT failed, [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
$result = null;
if (!mysqli_stmt_bind_result($stmt, $result)) {
printf("[%03d] Bind failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt)) {
printf("[%03d] Execute or fetch failed, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
$res = mysqli_stmt_result_metadata($stmt);
$meta = mysqli_fetch_fields($res);
mysqli_stmt_free_result($stmt);
$meta = $meta[0];
$length = $meta->length;
if ($length > strlen($insert)) {
$expected = str_repeat('0', $length - strlen($insert));
$expected .= $insert;
if ($expected !== $result) {
printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $result);
return false;
}
} else {
if ($length <= 1) {
printf("[%03d] Length reported is too small to run test\n", $offset);
return false;
}
}
return true;
}
示例9: db_query
function db_query($sql, $bind = null)
{
$db = get_var('db');
$query = false;
$stmt = mysqli_stmt_init($db);
$sql = trim($sql);
if (mysqli_stmt_prepare($stmt, $sql)) {
if (!empty($bind)) {
$types = '';
$values = array();
foreach ($bind as $key => &$value) {
$value = stripslashes($value);
if (is_numeric($value)) {
$float = floatval($value);
$types .= $float && intval($float) != $float ? 'd' : 'i';
} else {
$types .= 's';
}
$values[$key] =& $bind[$key];
}
$params = array_merge(array($stmt, $types), $bind);
call_user_func_array('mysqli_stmt_bind_param', $params);
}
if (mysqli_stmt_execute($stmt)) {
if (preg_match('/^(SELECT|SHOW)/i', $sql)) {
if (db_native_driver()) {
$query = mysqli_stmt_get_result($stmt);
mysqli_stmt_close($stmt);
} else {
return $stmt;
}
} else {
$query = TRUE;
mysqli_stmt_close($stmt);
}
} else {
trigger_error(mysqli_stmt_error($stmt), E_USER_WARNING);
}
} else {
trigger_error(mysqli_error($db), E_USER_WARNING);
}
return $query;
}
示例10: prepare
public function prepare($stmtName, $stmt, $values)
{
$prepStmt = \mysqli_prepare($this->connection, $stmt);
if (!$prepStmt) {
throw new \Exception('Prepared Statement prepare fail: ' . \mysqli_error($this->connection));
}
$types = '';
$binds = array($prepStmt, null);
for ($i = 0; $i < \count($values); $i++) {
$types .= self::getPrepareValueType($values[$i]);
$binds[] =& $values[$i];
}
$binds[1] = $types;
\call_user_func_array('mysqli_stmt_bind_param', $binds);
//you need 2 append the parameters - thats the right way to do that.
if (!mysqli_stmt_execute($prepStmt)) {
throw new \SYSTEM\LOG\ERROR("Could not execute prepare statement: " . \mysqli_stmt_error($prepStmt));
}
return new ResultMysqliPrepare($prepStmt, $this);
}
示例11: func_test_mysqli_stmt_num_rows
function func_test_mysqli_stmt_num_rows($stmt, $query, $expected, $offset)
{
if (!mysqli_stmt_prepare($stmt, $query)) {
printf("[%03d] [%d] %s\n", $offset, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d] [%d] %s\n", $offset + 1, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_store_result($stmt)) {
printf("[%03d] [%d] %s\n", $offset + 2, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if ($expected !== ($tmp = mysqli_stmt_num_rows($stmt))) {
printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 3, gettype($expected), $expected, gettype($tmp), $tmp);
}
mysqli_stmt_free_result($stmt);
return true;
}
示例12: getSubject
function getSubject($q, $front = false, $back = false)
{
if (strlen($q) < 1) {
return "none";
} else {
$con = $GLOBALS["con"];
$param = $q;
$sql = "";
if ($front || $back) {
if ($front == true) {
$param = "%" . $param;
}
if ($back == true) {
$param = $param . "%";
}
$sql = "SELECT Name FROM subjects WHERE Valid=1 AND Name LIKE ? LIMIT 1";
} else {
$sql = "SELECT Name FROM subjects WHERE Valid=1 AND Name=? LIMIT 1";
}
$stmt = mysqli_prepare($con, $sql) or die(mysqli_error($con));
mysqli_stmt_bind_param($stmt, 's', $param) or die(mysqli_stmt_error($stmt));
mysqli_stmt_execute($stmt) or die(mysqli_stmt_error($stmt));
mysqli_stmt_bind_result($stmt, $name);
if (mysqli_stmt_fetch($stmt)) {
return $name;
} else {
if ($back == false) {
return getSubject($q, false, true);
} else {
if ($front == false) {
return getSubject($q, true, true);
} else {
return getSubject(substr($q, 0, strlen($q) - 1), false, false);
}
}
}
}
}
示例13: getDocID
function getDocID($url)
{
$con = $GLOBALS["con"];
$sql = "SELECT docID FROM documents WHERE URL=?";
$stmt = mysqli_prepare($con, $sql) or die(mysqli_error($con));
mysqli_stmt_bind_param($stmt, 's', $url) or die(mysqli_stmt_error($stmt));
mysqli_stmt_execute($stmt) or die(mysqli_stmt_error($stmt));
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) < 1) {
mysqli_stmt_close($stmt);
$sql = "INSERT INTO documents (URL) VALUES (?)";
$stmt = mysqli_prepare($con, $sql) or die(mysqli_error($con));
mysqli_stmt_bind_param($stmt, 's', $url) or die(mysqli_stmt_error($stmt));
mysqli_stmt_execute($stmt) or die(mysqli_stmt_error($stmt));
mysqli_stmt_bind_result($stmt, $docID);
mysqli_stmt_fetch($stmt);
return getDocID($url);
} else {
mysqli_stmt_bind_result($stmt, $docID);
mysqli_stmt_fetch($stmt);
return $docID;
}
}
示例14: die
die('mysqli error: ' . mysqli_error($dbc));
}
//Bind parameters
mysqli_stmt_bind_param($stmt, "ssssssds", $firstName, $lastName, $email, $password, $streetAddress, $postalCode, $DOB, $gender);
if (!mysqli_execute($stmt)) {
die('stmt error: ' . mysqli_stmt_error($stmt));
}
//Query to get user ID
$query = "SELECT id FROM users WHERE email=?";
$stmt = mysqli_prepare($dbc, $query);
if (!$stmt) {
die('mysqli error: ' . mysqli_error($dbc));
}
mysqli_stmt_bind_param($stmt, "s", $email);
if (!mysqli_stmt_execute($stmt)) {
die('stmt error1: ' . mysqli_stmt_error($stmt));
}
mysqli_stmt_bind_result($stmt, $id);
while (mysqli_stmt_fetch($stmt)) {
$newUser = new User($id, $firstName, $lastName, $email, $password, $streetAddress, $postalCode, $DOB, $gender);
$newUser->sessionUser();
}
header('Location: WelcomePage.php');
}
function passwordChecker($p1, $p2)
{
if (strcmp($p1, $p2) != 0) {
exit("Passwords dont match, Goodbye");
} else {
return TRUE;
}
示例15: func_mysqli_stmt_bind_datatype
function func_mysqli_stmt_bind_datatype($link, $engine, $bind_type, $sql_type, $bind_value, $offset, $alternative = null)
{
if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL, label %s, PRIMARY KEY(id)) ENGINE = %s", $sql_type, $engine))) {
// don't bail - it might be that the server does not support the data type
return false;
}
if (!($stmt = mysqli_stmt_init($link))) {
printf("[%03d] [%d] %s\n", $offset + 1, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUE (?, ?)")) {
printf("[%03d] [%d] %s\n", $offset + 2, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
$id = 1;
if (!mysqli_stmt_bind_param($stmt, "i" . $bind_type, $id, $bind_value)) {
printf("[%03d] [%d] %s\n", $offset + 3, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
if (!mysqli_stmt_execute($stmt)) {
printf("[%03d] [%d] %s\n", $offset + 4, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
return false;
}
mysqli_stmt_close($stmt);
if (!($res = mysqli_query($link, "SELECT id, label FROM test"))) {
printf("[%03d] [%d] %s\n", $offset + 5, mysqli_errno($link), mysqli_error($link));
return false;
}
if (!($row = mysqli_fetch_assoc($res))) {
printf("[%03d] [%d] %s\n", $offset + 5, mysqli_errno($link), mysqli_error($link));
return false;
}
if ($alternative) {
if ($row['id'] != $id || $row['label'] != $bind_value && $row['label'] != $alternative) {
printf("[%03d] Testing '%s', '%s': expecting '%s'/'%s' (%s), got '%s'/'%s'\n", $offset + 6, $bind_type, $sql_type, $id, $bind_value, gettype($bind_value), $row['id'], $row['label']);
return false;
}
} else {
if ($row['id'] != $id || $row['label'] != $bind_value) {
printf("[%03d] Testing '%s', '%s': expecting '%s'/'%s', got '%s'/'%s'\n", $offset + 6, $bind_type, $sql_type, $id, $bind_value, $row['id'], $row['label']);
return false;
}
}
mysqli_free_result($res);
return true;
}