function getProduct($productId)
{
$st = $this->dbConn->prepare("SELECT * FROM tblproduct WHERE id = ?");
$st->bind_param("i", $productId);
$st->execute();
$data = $st->get_result();
$getProductResult = mysqli_fetch_all($data, MYSQLI_ASSOC);
$st->close();
return $getProductResult;
}
I'm confused what the Question Mark does? Wildcard?
$query = "UPDATE some_table set `name`=:name, `email`=:email WHERE `id`=:id";
$params=['email' => 'john@somedomain.xxx', 'name' => 'John', 'id' => 123];
$stmt = $conn->prepare($query);
$stmt->execute($params);
In the above query we can see exactly what values we are going to be using and in the $params array (where we supply the actual values) we can add them in any order.$people = [
(object)['fullName' => 'John', 'emailAddress => 'john@somedomain.xxx'],
(object)['fullName' => 'Jack', 'emailAddress => 'jack@somedomain.xxx'],
(object)['fullName' => 'Jim', 'emailAddress => 'jim@somedomain.xxx']
];
$query = "INSERT INTO some_table (`name`,`email`) VALUES(:name, email)";
$stmt = $conn->prepare($query);
foreach($people as $person) {
$params=[ 'name' => $person->fullName, 'email' => $person->emailAddress];
$stmt->execute($params);
}
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
mysqli
https://www.php.net/manual/en/mysqli.prepare
PDO
https://www.php.net/manual/en/pdo.prepare.php