Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » PostgreSQL »

Postgres con php bajo windows

Estas en el tema de Postgres con php bajo windows en el foro de PostgreSQL en Foros del Web. Hola tengo un problema estoy diseño una pagina en php y utilizo postgres ya hice la conexion entre php y postgres lo malo es que ...
  #1 (permalink)  
Antiguo 04/01/2007, 06:48
Avatar de Maria Karina  
Fecha de Ingreso: enero-2007
Mensajes: 2
Antigüedad: 17 años, 2 meses
Puntos: 0
Pregunta Postgres con php bajo windows

Hola tengo un problema estoy diseño una pagina en php y utilizo postgres ya hice la conexion entre php y postgres lo malo es que nose que codificacion debo utilizar para que me guarde los datos que tengo php en la base de datos de postgres. Y el otro problema que tengo es que codificación utilizo en php para que pueda baja los datos que tengo en la base de datos. Si alguien sabe le agradecere su ayuda.
  #2 (permalink)  
Antiguo 06/01/2007, 08:20
 
Fecha de Ingreso: mayo-2004
Ubicación: SurOeste de Guayaquil
Mensajes: 241
Antigüedad: 19 años, 9 meses
Puntos: 0
Re: Postgres con php bajo windows

ingresa a la pagina de

http://www.php.net
__________________
javier
  #3 (permalink)  
Antiguo 12/01/2007, 10:07
 
Fecha de Ingreso: agosto-2006
Mensajes: 141
Antigüedad: 17 años, 7 meses
Puntos: 0
Re: Postgres con php bajo windows

para conectar a la base de datos usa pg_connect("host=$dbhost user=$dbuser password=$dbpwd dbname=$dbname")
para sacar los datos usa pg_exec(aki escribe el select necesario entre comillas)
y para ingresar/actualizar/borrar usa pg_exec(aki la sentencia insert, update o delete necesaria)
  #4 (permalink)  
Antiguo 16/10/2009, 23:56
Avatar de yense  
Fecha de Ingreso: febrero-2008
Ubicación: Perú Lima
Mensajes: 340
Antigüedad: 16 años
Puntos: 3
Respuesta: Postgres con php bajo windows

hola man bueno me gustaria saber que debo de instalar para usar php apache y el postgre en windows veo que ya tienes experiencia en ello por fa

me puedes comentar de como hacer eso

gracias
  #5 (permalink)  
Antiguo 16/10/2009, 23:58
Avatar de yense  
Fecha de Ingreso: febrero-2008
Ubicación: Perú Lima
Mensajes: 340
Antigüedad: 16 años
Puntos: 3
Respuesta: Postgres con php bajo windows

por fa me puedes decir como usar el php y el postgre que debo de instalar y que editar bajo windows

gracias por todo
  #6 (permalink)  
Antiguo 16/10/2009, 23:59
Avatar de yense  
Fecha de Ingreso: febrero-2008
Ubicación: Perú Lima
Mensajes: 340
Antigüedad: 16 años
Puntos: 3
Respuesta: Postgres con php bajo windows

como uso el postgre y php en windows que debo de instalar y que hacer
  #7 (permalink)  
Antiguo 17/10/2009, 00:15
 
Fecha de Ingreso: octubre-2009
Ubicación: Caracas - Venezuela
Mensajes: 14
Antigüedad: 14 años, 5 meses
Puntos: 1
Respuesta: Postgres con php bajo windows

Hola M. Karina,

espero que esto te pueda se de utilidad:


11.2 Inserting and Retrieving Data
Connecting to the database is just not enough. In this section you will learn how to communicate with the database, how to create tables, and how to insert and retrieve data.

The first thing to do is to create a new table. Therefore you can write a short PHP script:

<?php
$connstr = "dbname=phpbook user=postgres host=localhost";
$dbh = pg_connect($connstr);
if ($dbh) {echo "connection to phpbook established ...<br>";}

$sql = "CREATE TABLE person (id serial, name text, location text)";
$stat = pg_exec($dbh, $sql);
if ($stat)
{
echo "The table has successfully been created<br>\n";
}
else
{
echo "creating the table failed<br>\n";
}
pg_close($dbh);
?>

After connecting to the database, a string containing the SQL code is generated. In the next step the query is sent to the server. pg_exec returns a status code that can be checked. Two parameters have to be passed to pg_exec: The first parameter is the connection handle and the second parameter contains the SQL statement you want to execute. If the statement has been executed successfully, the following text will be displayed:

connection to phpbook established ...
The table has successfully been created

To see if the table is really in the database, you can use psql and \d:

phpbook=# \d person
Table "person"
Attribute | Type | Modifier
-----------+---------+---------------------------------------------------
id | integer | not null default nextval('"person_id_seq"'::text)
name | text |
location | text |
Index: person_id_key

Now that you have created a table, you can start inserting records. The next example shows how one record can be added to the table:

<?php
$connstr = "dbname=phpbook user=postgres host=localhost";
$dbh = pg_connect($connstr);
if ($dbh) {echo "connection to phpbook established ...<br>";}

$sql = "INSERT INTO person (name, location) VALUES ('Paul', 'Vienna')";
$stat = pg_exec($dbh, $sql);
if ($stat)
{
echo "The record has been inserted successfully<br>\n";
}
else
{
echo "creating the table failed<br>\n";
}
pg_close($dbh);
?>

As you can see, adding records to the table works the same way as adding tables or executing any other SQL statement. In this regard, PHP is flexible and easy to use.

The text displayed by PHP is not surprising:

connection to phpbook established ...
The record has been inserted successfully

Now that the table contains some data, you can retrieve some records. Retrieving data is slightly more complex than inserting data or making other changes. To retrieve data, you must execute the query first. In the next step, the number of records in the result can be computed. Finally, the data can be retrieved using a simple loop as shown in the next listing:

<?php
$connstr = "dbname=phpbook user=postgres host=localhost";
$dbh = pg_connect($connstr);
if ($dbh) {echo "connection to phpbook established ...<br>";}

$sql = "SELECT id, name, location FROM person";
$stat = pg_exec($dbh, $sql);
if ($stat)
{
$rows = pg_numrows($stat);
echo "$rows lines returned by PostgreSQL<br>\n";
}
else
{
echo "an error has occurred while processing ($sql)<br>\n";
}
pg_close($dbh);
?>





Saludos,


Robert.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 2 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 04:30.