-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from SamuraiWTF/sqlite-support
Sqlite support
- Loading branch information
Showing
19 changed files
with
385 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vagrant | ||
ubuntu*.log | ||
*.retry | ||
.idea | ||
.idea | ||
sqlite_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Dockerfile.dojo-basic | ||
FROM php:7.4.27-apache-bullseye | ||
|
||
# Install dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
sqlite3 \ | ||
libsqlite3-dev \ | ||
dnsutils \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set the environment variable for database type | ||
ENV DOJO_DB_TYPE=sqlite | ||
|
||
COPY ./src/basic /var/www/html | ||
LABEL org.opencontainers.image.source=https://github.com/SamuraiWTF/samurai-dojo | ||
LABEL org.opencontainers.image.description="Basic PHP 7.4.27-apache-bullseye image with dojo-basic with sqlite support." | ||
LABEL org.opencontainers.image.licenses="lgpl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3' | ||
services: | ||
dojo-basic-lite: | ||
build: | ||
context: .. | ||
dockerfile: .shogun/Dockerfile.dojo-basic-lite | ||
ports: | ||
- "8080:80" | ||
environment: | ||
- DOJO_DB_TYPE=sqlite | ||
volumes: | ||
- ./sqlite_data:/var/www/html/db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
<?php mysqli_close($conn); ?> | ||
<?php | ||
// closedb.inc | ||
|
||
function db_close($conn) { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
$conn->close(); | ||
} else { | ||
$conn->close(); | ||
unset($conn); | ||
} | ||
} | ||
|
||
// Close the database connection | ||
db_close($conn); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,85 @@ | ||
<?php | ||
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die('Error connecting to mysql'); | ||
?> | ||
// opendb.inc | ||
|
||
function db_connect() { | ||
global $db_type, $dbhost, $dbuser, $dbpass, $dbname; | ||
|
||
if ($db_type === 'mysql') { | ||
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname); | ||
if ($conn->connect_error) { | ||
die("Connection failed: " . $conn->connect_error); | ||
} | ||
} else { | ||
$conn = new SQLite3('/var/www/html/db/' . $dbname . '.sqlite'); | ||
} | ||
|
||
return $conn; | ||
} | ||
|
||
function db_query($conn, $query) { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
$result = $conn->query($query); | ||
if (!$result) { | ||
die("Query failed: " . $conn->error . '<p><b>SQL Statement:</b>' . $query); | ||
} | ||
} else { | ||
$result = $conn->query($query); | ||
if (!$result) { | ||
die("Query failed: " . $conn->lastErrorMsg() . '<p><b>SQL Statement:</b>' . $query); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
function db_now() { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
return "NOW()"; | ||
} else { | ||
return "date('now')"; | ||
} | ||
} | ||
|
||
function db_num_rows($result) { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
return $result->num_rows; | ||
} else { | ||
$count = 0; | ||
$res = $result; | ||
while ($res->fetchArray()) { | ||
$count++; | ||
} | ||
$res->reset(); | ||
return $count; | ||
} | ||
} | ||
|
||
function db_fetch_assoc($result) { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
return $result->fetch_assoc(); | ||
} else { | ||
return $result->fetchArray(SQLITE3_ASSOC); | ||
} | ||
} | ||
|
||
function db_escape_string($conn, $string) { | ||
global $db_type; | ||
|
||
if ($db_type === 'mysql') { | ||
return $conn->real_escape_string($string); | ||
} else { | ||
return SQLite3::escapeString($string); | ||
} | ||
} | ||
|
||
// Establish the database connection | ||
$conn = db_connect(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.