<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
// $query = $this->db->get('news');
// Err: Call to undefined method CI_DB_odbc_driver::get()
$query = $this->db->query('SELECT * FROM news');
// This is good
return $query->result_array();
}
// $query = $this->db->get_where('news', array('slug' => $slug));
// Err: Call to undefined method CI_DB_odbc_driver::get_where()
// $query = $this->db->query('SELECT * FROM news WHERE slug = "' . $slug . '"');
// Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1
$query = $this->db->query('SELECT * FROM news', array('slug' => $slug));
// This allways gets only the first news, regardless of what the slug is.
return $query->row_array();
}
public function set_news()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'tecst' => $this->input->post('tecst')
);
// return $this->db->insert('news', $data);
// Err: Call to undefined method CI_DB_odbc_driver::insert()
// return $this->db->query('INSERT INTO news (title, slug, tecst) VALUES ("' .
// $this->input->post('title') . '", "' .
// $slug . '", "' .
// $this->input->post('tecst') . '")');
// Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3
return $this->db->query('INSERT INTO news (title, slug, tecst) VALUES (s, s, s);', $data);
// Err: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1
}
}