当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli_stmt_init函数代码示例

本文整理汇总了PHP中mysqli_stmt_init函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_stmt_init函数的具体用法?PHP mysqli_stmt_init怎么用?PHP mysqli_stmt_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mysqli_stmt_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: safeinsert

 public function safeinsert($table, $dataArray)
 {
     $field = "";
     $safeparam = "";
     $params = "";
     $paramarr = [];
     if (!is_array($dataArray) || count($dataArray) <= 0) {
         $this->halt('没有要插入的数据');
         return false;
     }
     $paramsnum = 0;
     while (list($key, $val) = each($dataArray)) {
         $nowtype = is_string($val) ? 's' : 'i';
         $paramarr[] = $val;
         $field .= "{$key},";
         $safeparam .= "?,";
         $paramsnum++;
         $params .= $nowtype;
         //之过滤字符串,int字形不用过滤
     }
     $field = substr($field, 0, -1);
     $safeparam = substr($safeparam, 0, -1);
     $sql = "insert into {$table}({$field}) values({$safeparam})";
     $stmt = mysqli_stmt_init($this->link);
     mysqli_stmt_prepare($stmt, $sql);
     array_unshift($paramarr, $stmt, $params);
     //把资源句柄和字符类型插入数组前两位
     //参数要传引用。具体见PHP手册mysqli_stmt_bind_param
     $parmlist = array();
     foreach ($paramarr as $key => $value) {
         $parmlist[$key] =& $paramarr[$key];
     }
     call_user_func_array("mysqli_stmt_bind_param", $parmlist);
     $result = mysqli_stmt_execute($stmt);
     $this->write_log("安全插入");
     if (!$result) {
         return false;
     }
     return true;
 }
开发者ID:Ostriches,项目名称:Yaf-Blog,代码行数:40,代码来源:Db.php

示例2: printf

    printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
    printf("[019] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
$id = $label = null;
if (!mysqli_stmt_bind_result($stmt, $id, $label)) {
    printf("[020] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
$row = mysqli_fetch_assoc($res);
if (NULL !== $id || NULL !== $label) {
    printf("[021] Bound variables should not have been set\n");
}
mysqli_free_result($res);
mysqli_stmt_close($stmt);
if (!($stmt = mysqli_stmt_init($link)) || !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") || !mysqli_stmt_execute($stmt)) {
    printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
    printf("[023] Expecting object/mysqli_result got %s/%s, [%d] %s\n", gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
}
if (!in_array($res->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT))) {
    printf("[024] Unknown result set type %s\n", $res->type);
}
if ($res->type !== MYSQLI_STORE_RESULT) {
    printf("[025] Expecting int/%d got %s/%s", MYSQLI_STORE_RESULT, gettype($res->type), $res->type);
}
mysqli_free_result($res);
mysqli_stmt_close($stmt);
mysqli_close($link);
if (NULL !== ($res = mysqli_stmt_get_result($stmt))) {
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_mysqli_tests_mysqli_stmt_get_result2.php

示例3: insertItems

 public function insertItems(Items $items)
 {
     $con = self::openConnection();
     $affected = 0;
     mysqli_begin_transaction($con);
     $stm = mysqli_stmt_init($con);
     $sql = "INSERT INTO product VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     mysqli_stmt_prepare($stm, $sql);
     foreach ($items->getItems() as $item) {
         $code = $item->getCode();
         $articul = $item->getArticul();
         $name = $item->getName();
         $bmuID = $item->getBasicMeasurementUnit() == null ? null : $item->getBasicMeasurementUnit()->getId();
         $price = $item->getPrice();
         $curID = $item->getCurrency() == null ? null : $item->getCurrency()->getId();
         $muID = $item->getMeasurementUnit() == null ? null : $item->getMeasurementUnit()->getId();
         $parent = $item->getParent() == null ? null : $item->getParent()->getCode();
         mysqli_stmt_bind_param($stm, 'sssdddds', $code, $articul, $name, $bmuID, $price, $curID, $muID, $parent);
         mysqli_stmt_execute($stm);
         if (mysqli_affected_rows($con) == 1) {
             $affected++;
         }
     }
     if ($affected > 0) {
         mysqli_commit($con);
     } else {
         mysqli_rollback($con);
     }
     return $affected;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:30,代码来源:ProductDAO.php

示例4: update_vote

function update_vote($image_id)
{
    //get number of votes and update
    global $link;
    /*$result = mysqli_query($link, "SELECT `amount` FROM `votes_amount` WHERE `imageID`=".$image_id.";") or die(mysqli_error($link));
    	$amount = mysqli_fetch_assoc($result);
    	$new_amount = $amount['amount']+1;
    	mysqli_query($link, "UPDATE `votes_amount` SET `amount`=".$new_amount." WHERE `imageID`=".$image_id.";") or die(mysqli_error($link));*/
    $stmt = mysqli_stmt_init($link);
    mysqli_stmt_prepare($stmt, "SELECT `amount` FROM `votes_amount` WHERE `imageID`=?;") or die(mysqli_error($link));
    mysqli_stmt_bind_param($stmt, 'i', $image_id);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    mysqli_stmt_close($stmt);
    $amount = mysqli_fetch_assoc($result);
    $new_amount = $amount['amount'] + 1;
    $stmt = mysqli_prepare($link, "UPDATE `votes_amount` SET `amount`=" . $new_amount . " WHERE `imageID`=?;") or die(mysqli_error($link));
    mysqli_stmt_bind_param($stmt, 'i', $image_id);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_close($stmt);
    //return ajax data
    if (isset($_SESSION['id']) && !isset($_POST['action']) && !isset($_POST['votePic'])) {
        $data = array('new_amount' => $new_amount, 'imageID' => $image_id);
    } elseif (isset($_POST['action']) && $_POST['action'] == 'anonymous_voting') {
        //get another two images
        $result = mysqli_query($link, "SELECT * FROM `image` ORDER BY RAND() LIMIT 2;") or die(mysqli_error($link));
        $data = array();
        while ($row = mysqli_fetch_assoc($result)) {
            $data[] = $row;
        }
    }
    mysqli_close($link);
    return $data;
}
开发者ID:tinggao,项目名称:woofWarrior,代码行数:34,代码来源:vote.php

示例5: insertItems

 public function insertItems(Items $items)
 {
     $con = self::openConnection();
     $affected = 0;
     mysqli_begin_transaction($con);
     $stm = mysqli_stmt_init($con);
     $sql = "INSERT INTO category VALUES (?, ?, ?)";
     mysqli_stmt_prepare($stm, $sql);
     foreach ($items->getItems() as $item) {
         $code = $item->getCode();
         $name = $item->getName();
         $parent = $item->getParent() == null ? null : $item->getParent()->getCode();
         mysqli_stmt_bind_param($stm, 'sss', $code, $name, $parent);
         mysqli_stmt_execute($stm);
         if (mysqli_affected_rows($con) == 1) {
             $affected++;
         }
     }
     if ($affected > 0) {
         mysqli_commit($con);
     } else {
         mysqli_rollback($con);
     }
     return $affected;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:25,代码来源:CategoryDAO.php

示例6: 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;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:57,代码来源:mysqli_stmt_bind_param_type_juggling.php

示例7: mysqli_query_insert

function mysqli_query_insert($type, $len, $runs, $host, $user, $passwd, $db, $port, $socket)
{
    $errors = $times = array();
    foreach ($runs as $k => $run) {
        $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'] = microtime(true);
        do {
            if (!($link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
                $errors[] = sprintf("INSERT %s %dx = #rows  connect failure (original code = %s)", $type, $run, $flag_original_code ? 'yes' : 'no');
                break 2;
            }
            if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
                $errors[] = sprintf("INSERT %s %dx = #rows drop table failure (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                break 2;
            }
            if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, label %s)", $type))) {
                $errors[] = sprintf("INSERT %s %dx = #rows create table failure (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                break 2;
            }
            $label = '';
            for ($i = 0; $i < $len; $i++) {
                $label .= chr(mt_rand(65, 90));
            }
            $start = microtime(true);
            if (!($stmt = mysqli_stmt_init($link))) {
                $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_init() failed (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                break 2;
            }
            $ret = mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)");
            $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_init() + stmt_prepare()'] += microtime(true) - $start;
            if (!$ret) {
                $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_init() failed (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                break 2;
            }
            $start = microtime(true);
            $ret = mysqli_stmt_bind_param($stmt, 'is', $i, $label);
            $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_bind_param()'] += microtime(true) - $start;
            if (!$ret) {
                $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_bind_param failed (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                break 2;
            }
            for ($i = 1; $i <= $run; $i++) {
                $start = microtime(true);
                $ret = mysqli_stmt_execute($stmt);
                $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_execute()'] += microtime(true) - $start;
                if (!$ret) {
                    $errors[] = sprintf("INSERT %s %dx = #rows stmt_execute failure (original code = %s): [%d] %s", $type, $run, $flag_original_code ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
                    break 3;
                }
            }
            mysqli_stmt_close($stmt);
            mysqli_close($link);
        } while (false);
        $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'] = microtime(true) - $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'];
    }
    return array($errors, $times);
}
开发者ID:splitice,项目名称:mysqlnd_ms,代码行数:56,代码来源:mysqli_stmt_insert.php

示例8: 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;
}
开发者ID:gleamingthecube,项目名称:php,代码行数:53,代码来源:ext_mysqli_tests_mysqli_stmt_bind_result_format.php

示例9: 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_mysqli_stmt_bind_param_table_1")) {
        printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
        return false;
    }
    if (!mysqli_query($link, sprintf("CREATE TABLE test_mysqli_stmt_bind_param_table_1(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_mysqli_stmt_bind_param_table_1(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_mysqli_stmt_bind_param_table_1"))) {
        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;
}
开发者ID:alphaxxl,项目名称:hhvm,代码行数:50,代码来源:mysqli_stmt_bind_param.php

示例10: deleteJob

/**
 * This function removes record with id $_GET[ID'] from the table Jobs
 */
function deleteJob()
{
    global $db_conn;
    $redirectlocation = "index.php?action=jobs";
    $stmt = mysqli_stmt_init($db_conn);
    global $db_conn;
    $sql = "DELETE FROM `jobs` WHERE `JobID` = ?";
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        print "Failed to prepare statement\n";
    } else {
        mysqli_stmt_bind_param($stmt, "i", $_GET['id']);
        mysqli_execute($stmt);
        mysqli_stmt_close($stmt);
    }
    immediate_redirect_to($redirectlocation);
    // return to jobs
}
开发者ID:emiel150,项目名称:Marco-s-Corner,代码行数:20,代码来源:template.pcs.php

示例11: saveOrder

function saveOrder($dt)
{
    global $link, $basket;
    $goods = myBasket();
    $stmt = mysqli_stmt_init($link);
    $sql = 'INSERT INTO orders(title, author, pubyear,price, quantity, orderid, datetime)
          VALUES(?,?,?,?,?,?,?)';
    if (mysqli_stmt_prepare($stmt, $sql)) {
        return false;
    }
    foreach ($goods as $item) {
        mysqli_stmt_bind_param($stmt, 'ssiiisi', $item['title'], $item['author'], $item['pubyear'], $item['price'], $item['quantity'], $basket['orderid'], $dt);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_close($stmt);
        setcookie('basket', "", time() - 3600);
        return true;
    }
}
开发者ID:spacediver,项目名称:php2,代码行数:18,代码来源:lib.inc.php

示例12: 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;
}
开发者ID:londomloto,项目名称:immortal,代码行数:43,代码来源:database.php

示例13: executeQuery

function executeQuery($conn, $sql, array $parameters = []){
	/*For matching the data type for binding*/
	$typesTable = [
		'integer' => 'i',
		'double' => 'd',
		'string' => 's'
	];
	$type = '';
	$stmt = mysqli_stmt_init($conn);
	
	if (!mysqli_stmt_prepare($stmt, $sql)){
		raiseIssue('failed to prepare statement');
		return false;
	}
	/*This bit should only run if any parameters are provided*/
	if (!empty($parameters)){
		foreach ($parameters as $parameter){
			/*Look up the type from the types table */
			$type .= $typesTable[gettype($parameter)];
		}
		array_unshift($parameters, $stmt, $type);
		/*bit hacky because of call_user_func_array, it will not like $parameters by itself so it needs to be "passed in by reference" but calltime pass by reference is deprecated*/
		$preparedParams = [];
		foreach ($parameters as $index => &$label){
			$preparedParams[$index] = &$label;
		}
		
		call_user_func_array('mysqli_stmt_bind_param', $preparedParams);
	}
	mysqli_stmt_execute($stmt);
	
	/*Generating the result set for use. This gives you the column names as keys on each row*/
	$result = mysqli_stmt_get_result($stmt);
	$resultSet = [];
	if(!$result){ return $resultSet; /*skips the result fetching if no results obtained*/}
	while ($row = mysqli_fetch_assoc($result)){
		$resultSet[] = $row;
	}
	mysqli_stmt_close($stmt);
	
	return $resultSet;
}
开发者ID:arielrossanigo,项目名称:trabajo_final,代码行数:42,代码来源:gb4etgDE.PHP

示例14: insertUnits

 public function insertUnits(Units $units)
 {
     $con = self::openConnection();
     $affected = 0;
     mysqli_begin_transaction($con);
     $stm = mysqli_stmt_init($con);
     $sql = "INSERT INTO currency (code) VALUE (?)";
     mysqli_stmt_prepare($stm, $sql);
     foreach ($units->getUnits() as $unit) {
         $code = $unit->getCode();
         mysqli_stmt_bind_param($stm, 's', $code);
         mysqli_stmt_execute($stm);
         if (mysqli_affected_rows($con) == 1) {
             $affected++;
         }
     }
     if ($affected > 0) {
         mysqli_commit($con);
     } else {
         mysqli_rollback($con);
     }
     return $affected;
 }
开发者ID:Voww,项目名称:PHP_test_tasks,代码行数:23,代码来源:CurrencyDAO.php

示例15: add_login

function add_login($user_id, $username, $passwd)
{
    if (!($db_link = get_connection())) {
        return -1;
    }
    $sql = 'insert into login (id, username, passwd) values (?,?,?)';
    $stmt = mysqli_stmt_init($db_link);
    if (mysqli_stmt_prepare($stmt, $sql)) {
        mysqli_stmt_bind_param($stmt, 'iss', $user_id, $username, $passwd);
        if (mysqli_stmt_execute($stmt)) {
            mysqli_stmt_close($stmt);
            mysqli_close($db_link);
            return 1;
        } else {
            mysqli_stmt_close($stmt);
            mysqli_close($db_link);
            return -2;
        }
    } else {
        mysqli_close($db_link);
        return -2;
    }
}
开发者ID:EVECP,项目名称:sailing,代码行数:23,代码来源:register.php


注:本文中的mysqli_stmt_init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。