Skip to content
← Back to Community
database in php?
Profile icon
samba0648

How to use a database with PHP in repl.it and what type of database we can use?

Voters
Profile icon
ch1ck3n
Profile icon
ZZZZZZ8
Profile icon
AryanPanwar
Profile icon
samba0648
Comments
hotnewtop
Profile icon
amasad

We don't have a good library for PHP right now but here is an example https://repl.it/@amasad/db-hello-world#index.php

Profile icon
theionceo

Here's a fan made library:

<?php // Replit DB function replitdb_set($key, $value) { $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => "$key=$value" ) ); $replitdb_url = getenv("REPLIT_DB_URL"); return file_get_contents($replitdb_url, false, stream_context_create($opts)); } function replitdb_get($key) { $replitdb_url = getenv("REPLIT_DB_URL"); return file_get_contents("$replitdb_url/$key"); } function replitdb_delete($key) { $opts = array('http' => array( 'method' => 'DELETE' ) ); $replitdb_url = getenv("REPLIT_DB_URL"); return file_get_contents("$replitdb_url/$key", false, stream_context_create($opts)); } ?>
Profile icon
bogi99

looking at it, and i have been here for only a day or so, repl seems to provide a key-value type storage, it does have some limitations check here https://docs.repl.it/misc/database .. so this is nothing like your normal database connection, it uses curl to perform the discrete functions of insert,delete,select and list. I think i may develop a wrapper/class in php for this to make it more usable ..

Profile icon
SixBeeps

Each DB will be different in terms of linking it to your code, but the process is the same on Repl.it as on a local machine. Your DB should have instructions on how to use it, if not online tutorials.

Profile icon
samba0648

I can't understand, will you explain it more [email protected]