Kieron Wiltshire
Kieron Wiltshire

Reputation: 81

How can I get a SQL enum as a string and check it against another string?

How can I use my prepared statement to retrieve the enum value of a specific user as a string and check it against another string in php?

Upvotes: 0

Views: 85

Answers (1)

user1475632
user1475632

Reputation: 196

If you are using PDO, you can do a select statement and check it against the string.

$conn = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$query = $conn->prepare("SELECT `what` FROM `users` WHERE `user_id` = ?");
$query->bindValue(1, $user_id);
try {
    $query->execute();
} catch (PDOException $e) {
    die($e->getMessage());
}
$dbValue = $query->fetchColumn();
if ($dbValue === 'string') {
    echo 'the db value does match the string.';
} else {
    echo 'the db value is not equal to the string.';
}

Upvotes: 1

Related Questions