[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">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250" />
</head>
<body>
<h1>Add news</h1>
<center><?=$this->validation->error_string; ?></center>
<?php echo form_open('formularz'); ?>
<p><label for="tytul">Title: </label><br /><?php echo form_input($tytul); ?></p>
<p><label for="tresc">Text: </label><br /><?php echo form_input($tresc); ?></p>
<?php echo form_submit('submit', 'Zapisz'); ?>
<?php echo form_close(); ?>
</body>
</html>
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!!!