I just want to make sure I'm describing this code in the correct way.
Is the line code $sql = "INSERT INTO MyGuests (firstname, lastname, email)VALUES ('John', 'Doe', '[email protected]')";
called mysql code? I just want to know the name of it for technical naming reasons.
I understand the rest is classed as PHP code but I wanted to know what is the technical name to describe the line specified above.
FULL CODE
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
CodePudding user response:
This code is PHP:
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
The above is an assignment of a string literal to a PHP variable called $sql
.
The string happens to contain SQL syntax. But so far, it is still just a string in PHP.
After you send that string to a MySQL Server, it is parsed by the SQL language parser in MySQL and then executed.
By analogy, a number like 1234 is just an integer. But if you enter it into a bank teller machine, it may turn out to be a PIN number. Is it a PIN before you enter it into the bank machine? That's a philosophical question.
CodePudding user response:
It is true. SQL is code language name Mysql is insert codes site.
This is sql code.
$sql="select * from user";//sql code
$mysqli->query($sql);//send to mysql server