从MYSQLi预处理语句中获取查询

时间:2016-05-16 07:17:45

标签: php mysql mysqli prepared-statement

我准备好的陈述如下:

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

// prepare and bind
$stmt = $conn->prepare("INSERT INTO `devices` (`deviceName`, `type`, `deviceToken`) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $deviceName, $deviceToken, $type);
$stmt->execute();
echo "executed";
$result = $stmt->get_result();
$conn->close();

我想回应一下这个问题。 我知道PDO方法:

$binded_query = $stmt->queryString

但我需要使用MYSQLi。
那我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

$sql = "INSERT INTO `devices` (`deviceName`, `type`, `deviceToken`) VALUES (?, ?, ?)"
$stmt = $conn->prepare($sql);
echo $sql; // here you go