MySQLi - Prepare
语法
mysqli_stmt mysqli_prepare ( mysqli $link , string $query )
定义和用法
它用于准备要执行的 SQL 语句。
示例
试试下面的例子 −
<?php $servername = "localhost:3306"; $username = "root"; $password = ""; $dbname = "TUTORIALS"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); exit(); } echo 'Success... ' . mysqli_get_host_info($conn) . " "; $stmt = $conn->prepare("INSERT INTO tutorials_auto (id, name) VALUES (?, ?)"); $stmt->bind_param("is", $id, $name); $id = "10"; $name = "sai"; $stmt->execute(); echo "New records created successfully"; $stmt->close(); $conn->close(); ?>
上述代码的示例输出应该是这样的 −
Success... localhost:3306 via TCP/IP New records created successfully