English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A função mysqli_stmt_init() inicializa a declaração e retorna o objeto usado por mysqli_stmt_prepare().
mysqli_stmt_init()A função mysqli_stmt_prepare() é usada para inicializar o objeto da declaração. O resultado desta função pode ser passado como um parâmetro para mysqli_stmt_prepare() Função.
mysqli_stmt_init($con);
Serial number | Parameters and descriptions |
---|---|
1 | con(Required) This is an object representing the connection with the MySQL Server. |
This function returns a statement object.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following example demonstratesmysqli_stmt_init()Function usage (procedural style)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "mydb"); $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; mysqli_query($con, $query); //Initialize statement $stmt = mysqli_stmt_init($con); $res = mysqli_stmt_prepare($stmt, "INSERT INTO Test values(?, ?)"); mysqli_stmt_bind_param($stmt, "si", $Name, $Age); $Name = 'Raju'; $Age = 25; print("Insert record....."); //Execute statement mysqli_stmt_execute($stmt); //End statement mysqli_stmt_close($stmt); //Close connection mysqli_close($con); ?>
Output result
Insert record.....
Here is another example of this function, initializing the declaration and returning the object used by mysqli_stmt_prepare():
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "mydb"); $query = "CREATE TABLE Test(Name VARCHAR(255), AGE INT)"; $con->query($query); //Initialize statement $stmt = $con->stmt_init(); $res = $stmt->prepare("INSERT INTO Test values(?, ?)"); $stmt->bind_param("si", $Name, $Age); $Name = 'Raju'; $Age = 25; print("Insert record....."); //Execute statement $stmt->execute(); //End statement $stmt->close(); //Close connection $con->close(); ?>
Output result
Insert record.....