Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Try out my first PHP web app! Reply To: Try out my first PHP web app!

#177593
__
Participant

How do I pull data from the database without a loop?

Depends on what api you are using. For example, with PDO:

$DB = new PDO( 
    'mysql:host=localhost;dbname=your_db;charset=UTF8',
    'mysql username',
    'mysql password'
);

$DB_getHash = $DB->prepare( 'select hash from users where username=?' );
$DB_getHash->execute( array( $_POST['username'] ) );
$queryResult = $DB_getHash->fetch();

if( 
    $queryResult 
    && password_verify( $_POST['password'],$queryResult['hash'] )
){
    // login successful
}
else{
    // login failed
}