Cara menggunakan postgresql html

Hallo blogger kali ini saya akan menjelaskan tentang cara koneksi database postgresql dengan php hingga menampilkan isi table di php. sebelumnya saya sudah menjelaskan tentang 

dengan harapan anda sudah tidak ada masalah untuk menjalankan database postgresql di windows 7. lansung saja masuk ke materi utama kita yaitu cara koneksi database postgresql dengan php.

Baca juga membuat koneksi database mysql dengan

yang pertama kita lakukan adalah login ke pgadmin jika anda lupa password anda dapat membaca postingan kami sebelumnya di mengubah atau mereset password.

jika sudah login silahkan buat database postgresql terlebih dahulu kemudian buat table dengan nama terserah anda. jika sudah membuat table dan mengisinya dengan beberapa data lakukan langkah-langkah berikut :

  1. masuk ke folder xampp\php\ edit php.ini dengan notepad++ atau editor apapun yang support / anda punya
  2. cari extension dengan nama
    extension=php_pdo_pgsql.dll
    extension=php_pgsql.dll

    aktifkan dengan cara hapus tanda ; (titik koma) didepannya

  3. buat folder didalam xampp\htdocs\ dengan nama terserah anda arifweb juga boleh :D

  4. jika sudah silahkan buat file php di dalam folder anda tadi dengan nama index.php

  5. isikan dengan kode php berikut ini

    <?php
    // script untuk memanggil fungsi php pg_connect untuk koneksi ke postgresql
    $conn = pg_connect("host=localhost port=5432 dbname=nama_database user='postgres'
    password='password_anda'");
    //disini nama database saya adalah nama_database
    $result = pg_prepare($conn, "my_query", 'SELECT * FROM mahasiswa');
    // disini saya membuat table dengan nama mahasiswa
    $result = pg_execute($conn, "my_query",array());
    echo "<table border='1px'>
    <tr><td> nim</td>
    <td> nama</td></tr>
    ";
    // kolom yang ada di table mahasiswa saya hanya ada 2 yaitu nim dan nama
    while ($row = pg_fetch_assoc($result))
    {
    echo "<tr>";
    echo "<td>".$row['nim']."</td>";
    echo "<td>".$row['nama']."</td>";
    echo "</tr>";
    }
    echo "</table>";
    ?>

  6. jika sudah silahkan jalankan di web browser anda dengan cara ketik localhost/nama_folder

saya harap tutoial ini bermanfaat bagi saya dan para pembaca. mungkin cukup sekian artikel saya kali ini tentang membuat koneksi database postgresql dengan php. jika artikel ini bermanfaat dan ada yang ingin ditanyakan silahkan masukkan ke kolom komentar terima kasih :)

Hargai penulis dengan berkomentar di bawah terima kasih :)

Once you have created a database, you can access it by:

  • Running the PostgreSQL interactive terminal program, called psql, which allows you to interactively enter, edit, and execute SQL commands.

  • Using an existing graphical frontend tool like pgAdmin or an office suite with ODBC or JDBC support to create and manipulate a database. These possibilities are not covered in this tutorial.

  • Writing a custom application, using one of the several available language bindings. These possibilities are discussed further in Part IV.

You probably want to start up psql to try the examples in this tutorial. It can be activated for the mydb database by typing the command:

$ psql mydb

If you do not supply the database name then it will default to your user account name. You already discovered this scheme in the previous section using createdb.

In psql, you will be greeted with the following message:

psql (15.0) Type "help" for help. mydb=>

The last line could also be:

mydb=#

That would mean you are a database superuser, which is most likely the case if you installed the PostgreSQL instance yourself. Being a superuser means that you are not subject to access controls. For the purposes of this tutorial that is not important.

If you encounter problems starting psql then go back to the previous section. The diagnostics of createdb and psql are similar, and if the former worked the latter should work as well.

The last line printed out by psql is the prompt, and it indicates that psql is listening to you and that you can type SQL queries into a work space maintained by psql. Try out these commands:

mydb=> SELECT version(); version -------------------------------------------------------------------​----------------------- PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit (1 row) mydb=> SELECT current_date; date ------------ 2016-01-07 (1 row) mydb=> SELECT 2 + 2; ?column? ---------- 4 (1 row)

The psql program has a number of internal commands that are not SQL commands. They begin with the backslash character, \. For example, you can get help on the syntax of various PostgreSQL SQL commands by typing:

mydb=> \h

To get out of psql, type:

mydb=> \q

and psql will quit and return you to your command shell. (For more internal commands, type \? at the psql prompt.) The full capabilities of psql are documented in psql. In this tutorial we will not use these features explicitly, but you can use them yourself when it is helpful.

Postingan terbaru

LIHAT SEMUA