Answers for "php mysql prepared in condition statement"

PHP
0

php prepared statement and conditional

$conn = getConnection();
$query = "SELECT first_name, last_name, description, title, message ,font_size , DATE_FORMAT(effective_date,'%h:%i %p %m-%d-%Y')
          FROM tbl_messages
          JOIN tbl_authors ON tbl_authors.id_author = tbl_messages.id_author
          JOIN tbl_locations ON tbl_messages.id_location = tbl_locations.id_location
          WHERE tbl_messages.id_location = IF(? = 1,tbl_messages.id_location,?)
          AND effective_date <= NOW()
          ORDER BY effective_date DESC
          LIMIT 1
          ";

if (!$stmt = $conn->prepare($query)) {
    return false;
}

$stmt->bind_param('ii', $location,$location);

$result = array();

$stmt->bind_result($first_name, $last_name, $location, $title, $message, $size, $date);
$stmt->execute();

while ($stmt->fetch()) {
    $m = new Message($first_name, $last_name, $location, $title, $message, $size, $date);
    array_push($result, $m);
}

return $result;
Posted by: Guest on August-27-2021
0

php prepared statements

$stmt->bind_param("i", $data); // Type: Integer
$stmt->bind_param("d", $data); // Type: Double
$stmt->bind_param("s", $data); // Type: String
$stmt->bind_param("b", $data); // Type: Blob
Posted by: Guest on August-27-2021

Code answers related to "php mysql prepared in condition statement"

Browse Popular Code Answers by Language