Langsung ke konten utama

how to install postgresql and use it with php on termux

first of all you need to install it:
apt install postgresql

then specify data dir for it by typing:
initd -D YOUR_DATA_DIR

example YOUR_DATA_DIR is /data/data/com.termux/files/home/mydb

note that you don't need to make the dir first, you just need the dir name then initdb will create it automatically :)

in this example like this:
initdb -D /data/data/com.termux/files/home/mydb

The files belonging to this database system will be owned by user "u0_a171".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory test ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... sysv
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Jakarta
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /data/data/com.termux/files/home/mydb -l logfile start

as it says, you can now run the db server :)
by typing:
pg_ctl -D /data/data/com.termux/files/home/mydb -l logfile start

after that, you need to install modules for working with it in php.
by typing:
apt install php-pgsql apr-util

now in the php side;
if you have nor already installed the install it first by typing:
apt install php

the edit the php.ini file in /data/data/com.termux/files/usr/lib/

edit by adding this section:
extension=pdo_pgsql.so
extension=pgsql.so

and save it

then test it now by typing:
php -a


the type the following:
$servername = "127.0.0.1";
$username = "";
$password = "";

try {
    $conn = new PDO("pgsql:host=$servername;dbname=postgres", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

it will says Connected successfully if you did follow this post correctly :)

note you can change /data/data/com.termux/files/home/mydb to ~/mydb for short too

chers~

Komentar

Postingan populer dari blog ini

How to export Godot game to Android from Linux

1.Go to Editor -> Manage export template -> Download and install ->Close. 2.Download command-tools cli for linux at https://developer.android.com/studio/ # command-tools .  Scroll down until you see the Command line tools  section. Then add `export ANDROID_HOME="/path/to/android-sdk"`  to your  `.bashrc`  or  `.zshrc` (for other shell, try to edit it accordingly), and unzip the file to: `/path/to/android-sdk/` Example: `$HOME/Android/android-sdk` 3.Download Openjdk latest version. Set JAVA _HOME  to your `.bashrc` : `export JAVA_ HOME=$(which java|rev|cut -d'/' -f3-|rev)` Install required tools&packages from sdkmanager: `$ANDROID _HOME/cmdline-tools/bin/sdkmanager --sdk_ root=$ANDROID_HOME "platform-tools" "build-tools;34.0.0" "platforms;android-34" "cmdline-tools;latest"` "cmake;3.10.2.4988404" "ndk;23.2.8568313" You can also choose which version you want to download, just playing around wi...

How to make J2ME Apps On Termux

To make J2ME Apps or maybe games, you will need to install OpenJDK (done via `apt install openjdk-xx` xx is the version number), Download the CLDC&MIDP jar files (download them from  jarcasting ). Create a new java file for the main program, called HelloMIDlet.java: ``` import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HelloMIDlet extends MIDlet {         private Display display;         private Form form;         public HelloMIDlet() {                 form = new Form("Hello World from J2ME!");         }         protected void startApp() {                 display = Display.getDisplay(this);                    form.append(new StringItem("Message:", "Hello, World!"));              ...

Cara install app/games yang tidak kompatibel di playstore

  tutor download atau beli game (graveyard keeper) yg tidak support di hp tanpa ribet: buka web playstore lalu login akun google kalian dan cari app/game yg dicari, misal graveyard keeper. klik beli dan pilih pembayaran (misal QRIS) dan selesaikan sampai muncul notif seperti di bawah. download aurora store, install dan beri ijin yg diperlukan (install app dan penyimpanan), login ke akun google kalian lalu cari app/game tadi dan langsung install aja. kalo ada pop up app tidak kompatibel, klik tombol selengkapnya dan proceed anyway. note: aurora store sering dipake buat install app/games yg tidak support atau tidak ada.