Note that there are some explanatory texts on larger screens.

plurals
  1. POOOP: Function to check if value is in database
    primarykey
    data
    text
    <p>I'm trying to create a user management system class and one of my functions is to check if a value is in a column in the database. It returns nothing at all.</p> <p>Here is the relevant information:</p> <pre><code>require("opperators/connect.php"); class UserManagemen { protected $db; public function __construct(PDO $db) { $this-&gt;db = $db; } public function isInDatabase($checkIfThis, $isHere) { $stmt = $db-&gt;prepare("SELECT 1 from users WHERE $isHere = :$isHere"); $stmt-&gt;execute(array(':$isHere' =&gt; $checkIfThis)); if ($stmt-&gt;rowCount() &gt; 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-&gt;isInDatabase(Batman, username); </code></pre> <p>in connect.php: this worked in my procedural coding test.</p> <pre><code>$configurator['database'] = array( 'username' =&gt; 'root', 'password' =&gt; 'root', 'host' =&gt; 'localhost', 'db' =&gt; 'girlscouts', ); $options = array( PDO::MYSQL_ATTR_INIT_COMMAND =&gt; '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-&gt;getMessage()); } </code></pre> <p>I apologise in advance if this has been asked repeatedly, I've tried a google but returned nothing of value, possibly because I don't know what to google. I'm not big on asking for help but I'll give it a shot. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload