Prepared manual database query

Source

<?php

    $sql = "SELECT * FROM customer WHERE id = ? OR id = ?";
    try {
        
    	$stmt = $this->db->pdo->prepare($sql);
    	$stmt->execute( array( 1,2 ) );
    	$this->view->result = $stmt->fetchAll(PDO::FETCH_OBJ);
    	
    } catch (\Exception $exception) {
    	
    	$this->view->flash('Database error', $exception->getMessage());
    	
    }

Result

stdClass Object
(
    [id] => 1
    [username] => Tester
    [password] => c098c977b6c9242f738ed521a63cb7e8
    [email] => test@example.com
    [created] => 2024-12-07
)
  • Barebone\Database\Connectors\PDO

    Barebone\Database\Connectors\PDO extends PDO
    • [M] __construct( $host, $user, $pass, $name ) : void
    • [M] get( string $tablename, array $where, string $orderby, string $limit, string $class_name ) : array
    • PDO

      PDO
      • [M] __construct( string $dsn, string $username, string $password, array $options ) : void
      • [M] connect( string $dsn, string $username, string $password, array $options ) : static
      • [M] beginTransaction() : void
      • [M] commit() : void
      • [M] errorCode() : void
      • [M] errorInfo() : void
      • [M] exec( string $statement ) : void
      • [M] getAttribute( int $attribute ) : void
      • [M] getAvailableDrivers() : void
      • [M] inTransaction() : void
      • [M] lastInsertId( string $name ) : void
      • [M] prepare( string $query, array $options ) : void
      • [M] query( string $query, int $fetchMode, mixed $fetchModeArgs ) : void
      • [M] quote( string $string, int $type ) : void
      • [M] rollBack() : void
      • [M] setAttribute( int $attribute, mixed $value ) : void