Initializes the declaration and returns the object used by mysqli_stmt_prepare():
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Modify the database connection character set to utf8mysqli_set_charset($con,"utf8");$country="CN";//Create a prepared statement $stmt=mysqli_stmt_init($con);if (mysqli_stmt_prepare($stmt,"SELECT name FROM websites WHERE country=?")){ // Bind parameters mysqli_stmt_bind_param($stmt,"s",$country); //Execute the query mysqli_stmt_execute($stmt); //Bind the result variable mysqli_stmt_bind_result($stmt,$name); //Get the value mysqli_stmt_fetch($stmt); printf( "%s The country's website is: %s",$country,$name); // Close the prepared statement mysqli_stmt_close($stmt);}mysqli_close($con);?>
The mysqli_stmt_init() function initializes the declaration and returns the object used by mysqli_stmt_prepare().
mysqli_stmt_init( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | Return an object. |
---|---|
PHP version: | 5+ |