| |

VerySource

 Forgot password?
 Register
Search
View: 13|Reply: 1

PHP connect PostgreSQL code?

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-2-7 11:00:01
| Show all posts |Read mode
Which prawns are there, send them quickly, thanks in advance
Reply

Use magic Report

0

Threads

26

Posts

15

Credits

Newbie

Rank: 1

Credits
15

 China

Post time: 2020-4-15 11:00:01
| Show all posts
<? php
// Connect, select database
$ dbconn = pg_connect ("host = localhost dbname = publishing user = www password = foo")
    or die ('Could not connect:'. pg_last_error ());

// execute SQL query
$ query = 'SELECT * FROM authors';
$ result = pg_query ($ query) or die ('Query failed:'. pg_last_error ());

// Display the result in HTML
echo "<table>\n";
while ($ line = pg_fetch_array ($ result, null, PGSQL_ASSOC)) {
    echo "\t <tr>\n";
    foreach ($ line as $ col_value) {
        echo "\t\t <td> $ col_value </ td>\n";
    }
    echo "\t </ tr>\n";
}
echo "</ table>\n";

// release result set
pg_free_result ($ result);

// close the connection
pg_close ($ dbconn);
?>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list