Heroku +PHP+DATABASE(PostgreSQL)

Today i start work on database on heroku. Its very simple orocess. Now i explain how to use the heroku PostgreSQL database.

First sign in your account.

Click on database and click on new database

Click create

After this they provide you full information about your database like :-dbusername,hostname,dbpassword,database.

now open your editor create a new file dbtable.php

<?php
$dbconn = pg_connect(“host=

port=

dbname=

user=

password=

sslmode=

require options=’–client_encoding=UTF8′”);
$qry=pg_query($dbconn,”Create table h ( name varchar(100),roll varchar(100))”)or die(“not work”);
?>

 

Now upload on heroku with this command

git init

git add .

git commit -m “commit status”

git push heroku master

Now again open your editor  and create insert.php file for insert the data

open your editor  and create show.php file for show the data

and again upload your application on heroku sever

<?php
$dbconn = pg_connect(“host=

port=

dbname=

user=

password=

sslmode=require

options=’–client_encoding=UTF8′”);
$qry=pg_query($dbconn,”select * from h”)or die(“not work”);
while($da=pg_fetch_array($qry)){
echo $da[‘name’];
}

Now open your application url and check every file function.

Example:-http://stormy-island-9821.herokuapp.com/in.php//for insert

http://stormy-island-9821.herokuapp.com/show.php//for show

 

 

Advertisements

One Comment Add yours

  1. adorgolap says:

    Thanks. It worked except the option = ’–client_encoding=UTF8′.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s