PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table mytable(id int, date datetime, project varchar(255), Duration int); insert into mytable values(1, "2022-01-30", "Project 1", 3), (2, "2022-01-30", "Project 1", 2), (3, "2022-01-30", "Project 2", 4), (4, "2022-01-29", "Project 3", 4), (5, "2022-01-28", "Project 3", 3), (6, "2022-01-28", "Project 3", 2); SELECT SUM(Duration) AS duration FROM mytable GROUP BY date
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; $now = Carbon::now()->format('d/m/Y'); printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion()); $query = "SELECT VERSION() as version;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version (PDO): %s ' . PHP_EOL, $row['version']); // Run query using mysqli $result = $mysqli->query($query); $version = $result->fetch_object(); printf('DB version (mysqli): %s ' . PHP_EOL, $version->version); // Select using Laravel $version = $db::select($db::raw("SELECT VERSION() as version;")); printf('DB version (Laravel Query Builder): %s ' . PHP_EOL, $version[0]->version); $sql = "SELECT id, date, project, duration FROM mytable order by date desc"; $result = $mysqli->query($sql); if ($result->num_rows > 0) { printf("Date Project Duration"); while($row = $result->fetch_assoc()) { printf( "%s %s %d \n", $row["date"], $row["project"], $row["duration"] ); } } else { echo "0 results"; }
Show:  
Copy Clear