I wrote a test program that looks more or less a program that performs the key functionality described above. Everything seems to be working fine. Can you explain how your program differs from this test program or provides its own test program?
<?php
$conn = pg_connect("host=localhost");
$result = pg_exec($conn,"drop table tvmobjects cascade;");
$result = pg_exec($conn,"create table tvmobjects (guid text not null, ipaddress text not null, username text not null, password text, hostid text not null, vmname text not null, guestostype text, guestosname text);");
function add_user($conn,$guid,$ip,$username,$password,$hostid,$name,$os)
{
$query = "INSERT INTO tvmobjects(guid,ipaddress,username,password,hostid,vmname,guestostype) VALUES($1, $2, $3, $4, $5, $6, $7)";
$result = pg_query_params($conn,$query,array($guid,$ip,$username,$password,$hostid,$name,strtolower($os)));
$no_records=pg_num_rows($result);
echo "Got $no_records in insert of $username\n";
}
add_user($conn,"james","1.2.3.4","james","semaj", "jamesid", "jamesvm", "jamesostype");
add_user($conn,"j'ames","1.2.3.5","j'ames","semaj", "j'amesid", "j'amesvm", "j'amesostype");
$query= "select vmname,guid,hostid,guestosname from tvmobjects";
$result = pg_query($conn,$query);
$no_records=pg_num_rows($result);
$j=$no_records;
$i=0;
while($row = pg_fetch_array($result))
{
if ($row[3]=="")
{
echo $row[0].'***'.$row[1].'***'.$row[2]."\n";
}
else
{
echo $row[0].' ( '.$row[3].' )'.'***'.$row[1].'***'.$row[2]."\n";
}
$i++;
}
?>
Running this for me generates:
Got 0 in insert of james
Got 0 in insert of j'ames
jamesvm***james***jamesid
j'amesvm***j'ames***j'amesid
As mentioned earlier, you do not insert a guest name when you insert a record, so the same output shown here does not contain an annotation (guestosname). But insertion and selection seem to work like a champion, so it's not clear what is wrong.