mysqli_stmt_param_count()函數(shù)返回給定語句的參數(shù)的數(shù)量。
mysqli_stmt_param_count()函數(shù)接受一個(準(zhǔn)備好的)語句對象作為參數(shù),并返回其中的參數(shù)標(biāo)記數(shù)。
mysqli_stmt_param_count($stmt)
| 序號 | 參數(shù)及說明 |
|---|---|
| 1 | stmt(必需) 這是表示執(zhí)行SQL查詢的語句的對象。 |
PHP mysqli_stmt_param_count()函數(shù)返回一個整數(shù)值,該整數(shù)值指示給定的預(yù)處理語句中參數(shù)標(biāo)記的數(shù)量。
此函數(shù)最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
假設(shè)我們已經(jīng)在MySQL數(shù)據(jù)庫中創(chuàng)建了一個名為employee的表,其內(nèi)容如下:
mysql> select * from employee; +------------+--------------+------+------+--------+ | FIRST_NAME | LAST_NAME | AGE | SEX | INCOME | +------------+--------------+------+------+--------+ | Vinay | Bhattacharya | 20 | M | 21000 | | Sharukh | Sheik | 25 | M | 23300 | | Trupthi | Mishra | 24 | F | 51000 | | Sheldon | Cooper | 25 | M | 2256 | | Sarmista | Sharma | 28 | F | 15000 | +------------+--------------+------+------+--------+ 5 rows in set (0.00 sec)
以下示例演示了 mysqli_stmt_param_count() 函數(shù)的用法(面向過程風(fēng)格)-
<?php
$con = mysqli_connect("localhost", "root", "password", "mydb");
$stmt = mysqli_prepare($con, "UPDATE employee set INCOME=INCOME-? where INCOME>=?");
mysqli_stmt_bind_param($stmt, "si", $reduct, $limit);
$limit = 20000;
$reduct = 5000;
//執(zhí)行語句
mysqli_stmt_execute($stmt);
print("記錄已更新......\n");
//受影響的行
$count = mysqli_stmt_param_count($stmt);
//結(jié)束語句
mysqli_stmt_close($stmt);
//關(guān)閉連接
mysqli_close($con);
print("受影響的行 ".$count);
?>輸出結(jié)果
記錄已更新...... 受影響的行 3
在面向?qū)ο箫L(fēng)格中,此函數(shù)的語法為$stmt->param_count;。以下是面向?qū)ο箫L(fēng)格中此函數(shù)的示例;
<?php
//建立連接
$con = new mysqli("localhost", "root", "password", "mydb");
$con -> query("CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
print("創(chuàng)建表.....\n");
$stmt = $con -> prepare( "INSERT INTO myplayers values(?, ?, ?, ?, ?)");
$stmt -> bind_param("issss", $id, $fname, $lname, $pob, $country);
$id = 1;
$fname = 'Shikhar';
$lname = 'Dhawan';
$pob = 'Delhi';
$country = 'India';
//執(zhí)行語句
$stmt->execute();
//記錄已更新
$count = $stmt ->param_count;
print("參數(shù)數(shù)量: ".$count);
//結(jié)束語句
$stmt->close();
//關(guān)閉連接
$con->close();
?>輸出結(jié)果
參數(shù)數(shù)量: 5