pg test
This commit is contained in:
		
							parent
							
								
									ec2583d930
								
							
						
					
					
						commit
						05972182a2
					
				| 
						 | 
					@ -0,0 +1,35 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$host = 'localhost';
 | 
				
			||||||
 | 
					$dbname = 'test';
 | 
				
			||||||
 | 
					$user = 'edpg';
 | 
				
			||||||
 | 
					$password = 'edpg';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Connect to the database
 | 
				
			||||||
 | 
					$db = pg_connect("host=$host dbname=$dbname user=$user password=$password");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!$db) {
 | 
				
			||||||
 | 
					  // connection failed
 | 
				
			||||||
 | 
					  echo "Error: Unable to open database\n";
 | 
				
			||||||
 | 
					} else {
 | 
				
			||||||
 | 
					  // connection succeeded
 | 
				
			||||||
 | 
					  echo "Opened database successfully\n";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Execute a query
 | 
				
			||||||
 | 
					$result = pg_query($db, "SELECT * FROM testab");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!$result) {
 | 
				
			||||||
 | 
					  // query failed
 | 
				
			||||||
 | 
					  echo "Error: Query failed\n";
 | 
				
			||||||
 | 
					} else {
 | 
				
			||||||
 | 
					  // query succeeded, loop through the rows
 | 
				
			||||||
 | 
					  while ($row = pg_fetch_row($result)) {
 | 
				
			||||||
 | 
					    echo "Name: $row[0]\n";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// close the connection
 | 
				
			||||||
 | 
					pg_close($db);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
		Loading…
	
		Reference in New Issue