Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9235833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:08:44+00:00 2026-06-18T07:08:44+00:00

I work on a web interface which receives and send informations to a distant

  • 0

I work on a web interface which receives and send informations to a distant PostGreSQL database.

From what I found on the internet it seems that the best way is to create a small php script in an external .php file.

I followed that idea,

so I have that script pg_connection.php which tests the connectivity to my database (with a pg_connect) in that style :

$db = pg_connect("host=localhost port=5432 dbname=**** user=**** password=****") 
or die("Not Connected");
if ($db) {echo (Connected);} else {echo (Not Connected);}

If I launch only that pg_connection.php in my webbrowser, it works fine (I just have wrotten Connected with the correct login infos entered in my script or Not connected if I put a random ip address).

Then in my .js(+jquery) external script I use :

$(document).ready(function(){
$("#dbstatus").load("php-services/pg_connection.php");
var dbstatus = new String();
dbstatus = $("#dbstatus").val();

if (dbstatus == "Connected")
{ /*jquery code to show a green light on a section in my html page*/}
else { /*jquery code to show a red light*/}
}

And that works partially :

In my $(“#dbstatus”) object it will replace the default text by Connected or Not Connected,
But it doesn’t produce any effect on the green/red light in my conditionnal

Then I went in my Chrome console and type dbstatus, and I realized that the content of my var is

<div id=​"dbstatus" class=​"span3">​Connected​</div>​

when I expected it to be just “Connected”.

Any idea on how to clean that var from all these extra html stuffs ?

Is there more simple method implemented in js or Jquery to check a postgreSQL database status ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:08:46+00:00Added an answer on June 18, 2026 at 7:08 am

    Try to modify your code to:

    $db = pg_connect("host=localhost port=5432 dbname=**** user=**** password=****") or die("0");
    if ($db) {echo "1";} else {echo "0"}
    

    And in JS:

    $(document).ready(function(){
      $.ajax({
        url: "http://fullpathto/php-services/pg_connection.php",
        cache: false
      }).done(function( result ) {
        if(result=="1") {
          /*jquery code to show a green light on a section in my html page*/
        }
        else
        {
          /*jquery code to show a red light*/}
        }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the company I work for has a web-based user interface which paying clients log
At work we have a web app that we'll need to interface with another
I work on a web app that involves scheduling. A user can view his
background: I work on an asp.net web application that is on a company intranet.
I am programming web interface which communicates with cisco switches via telnet. I want
I am to build a web application which will accept different events from external
I am working on a experimental website (which is accessible through web browser) that
I'm looking to implement a web interface with a number of items which can
Is that possible? I'm writing a web-admin interface for a network-system. I need to
I have a web interface to a system which has a left navigation. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.