Skip to content

Commit 0ae1a5a

Browse files
committed
Add hello world and crud benchmarks
1 parent 28eea08 commit 0ae1a5a

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config.php
2+
.idea/

crud.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require('config.php');
6+
7+
function error_500(string $message): void
8+
{
9+
header('HTTP/1.1 500 Internal Server Error');
10+
exit($message);
11+
}
12+
13+
function show_mysqli_error(mysqli $mysqli, int $line): void
14+
{
15+
if ($mysqli->error) {
16+
error_500('[' . $line . '] ' . $mysqli->error);
17+
}
18+
}
19+
20+
$mysqli = new mysqli($host, $user, $password, $database);
21+
if ($mysqli->connect_error) {
22+
error_500($mysqli->connect_error);
23+
}
24+
25+
// create
26+
$mysqli->query("
27+
INSERT INTO crud (firstName, lastName, email, message)
28+
VALUES ('Steevan', 'BARBOYON', 'steevan.barboyon@gmail.com', 'php-benchmarks, the first php benchmarks site !')
29+
");
30+
show_mysqli_error($mysqli, __LINE__);
31+
$id = $mysqli->insert_id;
32+
33+
// read
34+
$mysqli->query('SELECT * FROM crud WHERE id = ' . $id);
35+
show_mysqli_error($mysqli, __LINE__);
36+
37+
// update
38+
$mysqli->query("
39+
UPDATE crud
40+
SET firstName = 'InfoDroid', lastName = 'InfoDroid', email = 'contact@info-droid.fr', message = 'php-benchmarks, the ultimate php benchmarks site !'
41+
WHERE id = " . $id
42+
);
43+
show_mysqli_error($mysqli, __LINE__);
44+
45+
// delete
46+
$mysqli->query('DELETE FROM crud WHERE id = ' . $id);
47+
show_mysqli_error($mysqli, __LINE__);
48+
49+
$mysqli->close();

helloworld.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
echo 'Hello World !';

0 commit comments

Comments
 (0)