CodeIgniter Forums
Help with PostgreSQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Help with PostgreSQL (/thread-54673.html)



Help with PostgreSQL - El Forum - 09-19-2012

[eluser]Gabriel Melo[/eluser]
Hello.

I'm trying to develop an application with Codeigniter 2.1.2 and Postgre 8.3 on Windows Xp. I work with Xampp 1.6.7, Apache/2.2.9, PHP/5.2.6.

Here's the database.php code:

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'postgres';
$db['default']['password'] = 'password';
$db['default']['database'] = 'orfeo';
$db['default']['dbdriver'] = 'postgre';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

I did a basic Model, Controller and view:

Code Model:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Postgre_model extends CI_Model {

public function getMacroprocesos()
{
  $query = $this->db->select('macroproceso.nombre');
  $query = $this->db->get('macroproceso');
  return $this->query->result();
}
    

}

Controller code

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test_postgre extends CI_Controller {

    public function index()
    {
      $this->load->model('Postgre_model');
      $data['macroprocesos'] = $this->Postgre_model->getMacroprocesos();
      $this->load->view('test-view', $data);
    }

}


and the view code:

Code:
<html>
<head>
<title>Test Postgre Codeigniter</title>
</head>
<body>
<?php foreach ($macroprocesos as $macroproceso): ?>
  echo $macroproceso->nombre;
<?php endforeach ?>
</body>
</html>


So, when I try to test the results in the browser via http://localhost/sgi/index.php/test_postgre the app shows me this error message:

Quote:A Database Error Occurred

Error Number:

ERROR: relation "macroproceso" does not exist

SELECT "macroproceso"."nombre" FROM "macroproceso"

Filename: D:\Dropbox\sgi\system\database\DB_driver.php

Line Number: 330


I don't know what is happening. It's my first project with Codeigniter and PostgreSQL.

Thanks for help me.

Gabo


Help with PostgreSQL - El Forum - 09-21-2012

[eluser]Gabriel Melo[/eluser]
So, anybody could help me ? xD

Thanks


Help with PostgreSQL - El Forum - 09-21-2012

[eluser]Unknown[/eluser]
[quote author="Gabriel Melo" date="1348265020"]So, anybody could help me ? xD

Thanks[/quote]

A Database Error Occurred

Error Number:

ERROR: relation “macroproceso” does not exist

SELECT “macroproceso”.“nombre” FROM “macroproceso”

Filename: D:\Dropbox\sgi\system\database\DB_driver.php

Line Number: 330

A Guess. . .driver.php in D:\Dropbox? Should be root of host



Help with PostgreSQL - El Forum - 09-21-2012

[eluser]Gabriel Melo[/eluser]
[quote author="ktrollinger" date="1348277751"][quote author="Gabriel Melo" date="1348265020"]So, anybody could help me ? xD

Thanks[/quote]

A Database Error Occurred

Error Number:

ERROR: relation “macroproceso” does not exist

SELECT “macroproceso”.“nombre” FROM “macroproceso”

Filename: D:\Dropbox\sgi\system\database\DB_driver.php

Line Number: 330

A Guess. . .driver.php in D:\Dropbox? Should be root of host
[/quote]

Ok, I work with alias in the httpd.conf, I mean for develop at job and in my home, so I put the folder projects inside the dropbox folder. I have other projects in CI in the same folder and work very good, no problem, with mysql connection.


Help with PostgreSQL - El Forum - 09-22-2012

[eluser]Gabriel Melo[/eluser]
I'm sorry very much for that all happened, It just was a mistake of typing :/

I fixed the error, this was the next line:

Code:
$db['default']['database'] = 'orfeo';

The really line should be:

Code:
$db['default']['database'] = 'sgi';

And the next line in the model was wrong too:

Code:
return $this->query->result();

It must be:

Code:
return $query->result();

And now the query works ok, shows me the records from the database.

I was wrong with the database name, I'm sorry guys, I can't understand how we sometimes have mistakes and the days and hours pass and we can't find the errors.


Thank you very much for all your support.

Gabo.