I'm going to share how to setup grocerycrud with mssql2005, (grocerycrud is superawesome tool, the design is clean and perform fast too ! ,shame if we can't use it)
first we have to make sure that our (XAMPP or WAMP or another platform) and CI is integrated with mssql2005,
and then the grocerycrud setup. Install grocerycrud like usuall after succed installing grocerycrud.
follow this step:
1. at application/config/database.php change the
$db['default']['dbdriver'] = 'mysql'; to mssql
2. at system/database/DB_driver.php change the
var $dbdriver to mssql
3. at application/models/grocery_crud_models.php at function
get_field_types_basic_table()
{
$sql = "select column_name as Field, data_type+'('+convert(varchar(255), character_maximum_length)+')' as Type, is_nullable as [Null], case when ordinal_position = 1 then 'PRI' else '' end as [Key], column_default as [Default], '' as Extra from information_schema.columns where table_name = '{$this->table_name}'";
$db_field_types = array();
//foreach($this->db->query("SHOW COLUMNS FROM {$this->table_name}")->result() as $db_field_type)
foreach($this->db->query($sql)->result() as $db_field_type
}
copy this code for the first 4 row code, mssql don't have show columns so we exchange with the $sql the result is exactly like mysql's show column
4. and then make your own model at the model folder
<?php
class MY_grocery_Model extends grocery_CRUD_Model {
function get_primary_key($table_name = null)
{
if($table_name == null)
{
return 'your_field_name'; // <-------- change this line here, write your table's primary key there
}
else
{
$fields = $this->get_field_types($table_name);
foreach($fields as $field)
{
if($field->primary_key == 1)
{
return $field->name;
}
}
return false;
}
}
}
5. make sure you include your model at controller like this
$crud->set_model("MY_grocery_model");
$crud->set_table("mytable"); // above where you set your table, i set it like that
after this point your grocerycrud should be successfully viewed, you can update and add. but not delete
here's the last step
6.at system\database\drivers\mssql\mssql_driver.php
find this function : function _delete (line 607 in my computer)
remove the $limit
at return (line 625 in my comp) you should have this kind of code
return " DELETE FROM "[color=#000000].$table.$conditions;
be sure that your condition doesn't wrong, i misstype once and that table deleted entirely, or you can use select top
the delete function cannot be used because i find that mssql don't have limit function like mysql do
that's all. Hope this helps who want to use grocerycrud with mssql
![:D](/public/style_emoticons/default/biggrin.png)
Happy crudding