Welcome Guest, Not a member yet? Register   Sign In
firebird 2.0 gen_id
#1

[eluser]polish[/eluser]
Hi,
I have a problem with autoincrement in my database table:

CREATE TABLE NEWS (
NEWS_ID SMALLINT NOT NULL,
NEWS_TITLE VARCHAR(100),
NEWS_TEXT VARCHAR(255)
);


I have create a procdure:

SET TERM ^ ;
CREATE PROCEDURE SP_GEN_NEWS_ID
returns (
id integer)
as
begin
id = gen_id(gen_news_id, 1);
suspend;
end^
SET TERM ; ^
GRANT EXECUTE ON PROCEDURE SP_GEN_NEWS_ID TO SYSDBA;


and a generator:

CREATE GENERATOR GEN_NEWS_ID;
SET GENERATOR GEN_NEWS_ID TO 0;


This is my controller php file:

<?php
class Formularz extends Controller
{
function index()
{
$news_id = 'gen_id(gen_news_id, 1)';
//$news_id['id'] = array('name' => 'gen_id(gen_news_id, 1)');
$data['tytul'] = array('name' => 'tytul');
$data['tresc'] = array('name' => 'tresc');

$rules['tytul'] = "required";
$rules['tresc'] = "required";
$this->validation->set_rules($rules);

if ($this->validation->run() == FALSE)
{
$data['tytul']['value'] = $this->input->post('tytul');
$data['tresc']['value'] = $this->input->post('tresc');
$this->load->view('form', $data);
}
else
{
$this->load->model('News');
$this->News->add_news(array('NEWS_ID' => $news_id, 'NEWS_TITLE' => $this->input->post('tytul'), 'NEWS_TEXT' => $this->input->post('tresc')));
echo 'Execute';
}
}
}
?>


php model file:

<?php
class News extends Model
{
function News()
{
parent::Model();
}
function get_news()
{
$this->db->orderby("NEWS_ID", "desc");
return $this->db->get('NEWS');
}
function add_news($data)
{
return $this->db->insert('NEWS', $data);
}
function update_news($id, $data)
{
$this->db->where('NEWS_ID', $id);
return $this->db->update('NEWS', $data);
}
function delete_news($id)
{
$this->db->where('NEWS_ID', $id);
return $this->db->delete('NEWS');
}
}
?>


end php wiev file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=windows-1250" /&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>Add news</h1>
<center>&lt;?=$this->validation->error_string; ?&gt;</center>
&lt;?php echo form_open('formularz'); ?&gt;
<p><label for="tytul">Title: </label><br />&lt;?php echo form_input($tytul); ?&gt;</p>
<p><label for="tresc">Text: </label><br />&lt;?php echo form_input($tresc); ?&gt;</p>
&lt;?php echo form_submit('submit', 'Zapisz'); ?&gt;
&lt;?php echo form_close(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;


The connection is correct but INSERT into NEWS didn't work!

How can I use this generator with this files to inserting data into my table NEWS????

Thank's!!!


Messages In This Thread
firebird 2.0 gen_id - by El Forum - 01-25-2008, 10:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB