$PG = @pg_connect ("Host=localhost user=postgres password=sa Dbname=employes") Or Die ("can ' t connect to database."); $query = "SELECT * from Employes order by Serial_no"; $query = "INSERT into employes values (10008, ' Susan ', ' 1985-09-04 ', ' 80 ', ' 50 ')"; $result = @pg_query ($PG, $query) or Die ("can" t run query to table.); echo pg_num_rows ($result); Output how many records are queried if ($result) //{ echo "Recrods inserted sucessfully!"; echo pg_affected_rows ($result);//Output How many records are inserted //} instance one [Pg_fetch_row] echo "<table border=1>"; echo "<tr>"; echo "<td>serial_no</td>"; echo "<td>name</td>"; echo "<td>birthday</td>"; echo "</tr>"; for ($i =0; $i <pg_num_rows ($result); $i + +) { $row = @pg_fetch_row ($result) or Die ("can ' t fetch row from table."); $serial _no= $row [0]; $name = $row [1]; $birthday = $row [2]; echo "<tr>"; echo "<td> $serial _no</td>"; echo "<td> $name </td>"; echo "<td> $birthday </td>"; echo "</tr>"; } echo "</table>"; //Instance two [Pg_fetch_array] //echo "<table border=1>"; //echo "<tr>"; //echo "<td>serial_" No</td> "; //echo "<td>name</td>"; //echo "<td>birthday</td>"; //echo "</tr>"; // //for ($i =0 $i <pg_num_rows ($result); $i + +) //{ // /$row = @pg_fetch_array ($result) or Die (" Can ' t fetch row from table. '); //$serial _no= $row [' serial_no ']; //$name = $row [' name ']; //$birthday = $row [' Birthday ']; //echo "<tr>"; //echo "<td> $serial _no</td>"; //echo "<td> $name </td>"; //echo "<td> $birthday </td>"; //echo "</tr>"; // //} //echo "</table>"; //Add, delete, modify instance //$newrow =array ("Serial_no" => "1006", "name" => "Peter", "Birthday" => "1990-07-03", " Salary "=>", "bonus" => "80"); //$reusult = @pg_insert ($PG, "employes", $newrow) or Die ("can" insert data to table.); //if ($reusult) //{ //echo "rechords inserted sucessfully!"; //} // Pg_close ($PG); |