sql - How to select a database in Postgres with PHP? -


i have following string connection:

$string_connection = "host=localhost port=5432 user=postgres password=postgres"; $conn = pg_connect($string_connection ); 

later in code, need select database:

pg_connect("dbname=my_database"); 

but, have following error:

warning: pg_connect(): unable connect postgresql server: fe_sendauth: no password supplied in ..\class.databases.php on line 142 

but, in example of php.net, this. example:

pg_query($conn,'\connect my_database'); 

why dont work?

when backup pgadmin, got following strings:

set statement_timeout = 0; set client_encoding = 'utf8'; set standard_conforming_strings = off; set check_function_bodies = false; set client_min_messages = warning; set escape_string_warning = off;  drop database my_database;  create database my_database encoding = 'utf8' lc_collate = 'portuguese_brazil.1252' lc_ctype = 'portuguese_brazil.1252';  alter database my_database owner postgres;  \connect my_database 

whe try run script pg_query, have erros:

warning: pg_query(): query failed: erro: syntax error in "\" line 1: \connect my_database ^ 

i need select dabatase create schema create tables... dont know how postgres.

add "dbname=my_database" connection string select database @ conection time.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -