ユーザー管理システムクラスを作成しようとしています。私の機能の1つは、データベースの列に値があるかどうかを確認することです。何も返しません。
関連情報は次のとおりです。
require("opperators/connect.php");
class UserManagemen
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function isInDatabase($checkIfThis, $isHere)
{
$stmt = $db->prepare("SELECT 1 from users WHERE $isHere = :$isHere");
$stmt->execute(array(':$isHere' => $checkIfThis));
if ($stmt->rowCount() > 0) {
echo "It's in the database";
} else {
echo "Not in the database and you are good to go!";
}
}
}
$usermanagement = new UserManagemen($db, null, null, null);
$usermanagement->isInDatabase(Batman, username);
connect.phpで:これは私の手続き型コーディングテストで機能しました。
$configurator['database'] = array(
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'db' => 'girlscouts',
);
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
);
try {
$db = new PDO("mysql:host={$configurator['database']['host']};dbname={$configurator['database']['db']};charset=utf8", $configurator['database']['username'], $configurator['database']['password'], $options);
}
catch (PDOException $ex) {
die("Failed to connect to the database: " . $ex->getMessage());
}
これが繰り返し尋ねられた場合は、事前にお詫び申し上げます。グーグルを試しましたが、何をグーグルするかわからないためか、何の価値もありませんでした。私は助けを求めるのは大したことではありませんが、それを試してみます。