title: how to use php variables in postgresql query
body: <p>I have two php variables, one integer and other json, which I convert into string variable and then inserting them inside a postgresql database.</p>
  
  <p>Converting integer into string variable:</p>
  
  <pre><code>$string1 = (string)$integer;
  </code></pre>
  
  <p>Coneverting json from facebook api into string variable:</p>
  
  <pre><code>$string2 = json_encode($json);
  </code></pre>
  
  <p>Now, I have to insert these two string variables into postgres database:</p>
  
  <pre><code>$query = "INSERT INTO interests VALUES(". $string1 ." ," . $string2 .")"; 
  pg_query($con, $query) or die("Cannot execute query: $query\n");
  </code></pre>
  
  <p>This is not working. I have tried a lot of solutions but still not working. </p>
  
  <p>I changed my function to insert into database</p>
  
  <pre><code>function push_interests(){
  $id = $facebook-&gt;getUser();
  $int = $facebook-&gt;api('/me/interests');     
  $host = "hostname"; 
  $user = "user"; 
  $pass = "password"; 
  $db = "database"; 
  
  $con = pg_connect("host=$host dbname=$db user=$user password=$pass")
      or die ("Could not connect to server\n"); 
  
  
  $id = (string)$id;
  $int = json_encode($int);
  
  $sql = "INSERT INTO interests VALUES($1,$2)"; 
  pg_prepare($con,'my_insert', $sql) or die ("Cannot prepare statement1\n") ;
  pg_execute($con,'my_insert', array($id,$int)) or die ("Cannot execute statement1\n");
  
  pg_close($con); 
  
  }
  </code></pre>
  
  <p>Output is: cannot execute statement1
  I have created database as below:</p>
  
  <pre><code>$query = "DROP TABLE IF EXISTS interests"; 
  pg_query($con, $query) or die("Cannot execute query: $query\n");
  
  $query = "CREATE TABLE interests(id VARCHAR(25) PRIMARY KEY, interests VARCHAR(500))";  
  pg_query($con, $query) or die("Cannot execute query: $query\n"); 
  </code></pre>