If you are using mysql database, then use the following -
$query = "SELECT username from my_table where username='bob'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
// row exists. do whatever you would like to do.
}
If you would like to use PDO (PHP Data Object)
, as alex suggested, then use the following code -
$dbh = new PDO("mysql:host=your_host_name;dbname=your_db_name", $user, $pass);
$stmt = $dbh->prepare("SELECT username from my_table where username = ':name'");
$stmt->bindParam(":name", "bob");
$stmt->execute();
if($stmt->rowCount() > 0)
{
// row exists. do whatever you want to do.
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…