viernes, 14 de febrero de 2025

prepare sttament

 <?php


mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");


// Check for connection errors

if ($mysqli->connect_error) {

    die("Connection failed: " . $mysqli->connect_error);

}

/* Prepare an insert statement */

$stmt = $mysqli->prepare("INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)");


// Check if the statement was prepared successfully

if (!$stmt) {

    die("Error preparing the statement: " . $mysqli->error);

}


/* Bind variables to parameters */

$stmt->bind_param("sss", $val1, $val2, $val3);


$val1 = 'Stuttgart';

$val2 = 'DEU';

$val3 = 'Baden-Wuerttemberg';


/* Execute the statement */

if ($stmt->execute()) {

    printf("New record has ID %d.\n", $mysqli->insert_id);

} else {

    echo "Error inserting record: " . $stmt->error;

}


// Close the connection

$mysqli->close();

?>

No hay comentarios:

Publicar un comentario