Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP pg_connect to PostgreSQL

Name: Anonymous 2013-12-21 6:44

Trying to use PHP to remotely query a PostgreSQL DB on my AWS server..


<?php

    if ( isset($_POST["searchText"]) )
    {
        $searchText  = $_POST["searchText"];
        $searchType  = $_POST["searchType"];
        $searchDb  = $_POST["searchDb"];
    }
   
    $query = "SELECT * FROM " . $searchDb . " WHERE " . $searchType . " = '" . $searchText . "';";
   
    $queryResult = query($searchDb, $query);
    //echo $queryResult;
 
    function query($searchDb, $query)
    {
        $host = "wouldntyouliketoknow.com";
        $user = "username";
        $pass = "password";
        $db = "database";
       
        pg_connect("host=$host port=5432 dbname=$db user=$user password=$pass");
       
        if (!$conn)
        {
            echo "Not connected";
        }
   
        $result = pg_query($conn, $query);
        pg_close($conn);
        return $result;
    }
   
?>


It doesn't throw any errors, the connection request just times out every time after like 15 seconds, then it just echoes "Not connected." Is this an issue with the AWS server, or the server I'm trying to open the connection from?

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-12-21 9:34

>>3
OP needs to use this: http://php.net/mysql_real_escape_string

(Ignore that it's MySQL, any *SQL needs the same escaping done. There is no postgresql_real_escape_string.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List