Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Query a database table

Johan Strydom edited this page Aug 13, 2021 · 3 revisions

First you need to connect to the database.

For this example we created the following table in our database:

CREATE TABLE my_new_table (
	`ID` INT AUTO_INCREMENT PRIMARY KEY,
	`DATE_CREATED` DATETIME DEFAULT CURRENT_TIMESTAMP,
	`SOMETHING` VARCHAR(255)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

Via TsamaDatabase you can now query the table using the $db->Query() method as follows:

$myData = $db->Query('SELECT `ID`, `DATE_CREATED`,`SOMETHING` FROM `my_new_table`');

if($myData->rowCount() > 0){
        Debug::Log("RowCount:" . $myData->rowCount());
        while($tableRow = $myData->fetch(\PDO::FETCH_OBJ)){
          echo '<p>'.$tableRow->ID.':'.$tableRow->DATE_CREATED.' - '. $tableRow->SOMETHING .'</p>';
        }
}

NEXT » Adding a form «