Welcome Guest, Not a member yet? Register   Sign In
simple dbforge oddity causes newbie,s brain to fade
#1

[eluser]ciPhil[/eluser]
below is a simple script that is part of my learning of ci .
I have no idea where even to think of looking.

Is my code and logic ok ?
Any ideas appreciated
comments at end explain problem
Cheers
Phil

<?php



class Phil extends Controller {



function Phil()

{

parent::Controller();

}



function index()

{

$this->load->database();
$this->load->dbforge();

// a manual test is required with postgresql, IF EXISTS in version 8.2
If ($this->db->table_exists('phil'))
{

echo " table named phil exists";
echo "<br/>";
$this->dbforge->drop_table('phil');
echo "dropped table named phil";
}else{
echo "table did not exist";

}


$fields = array(
'id'=>array(
'type'=> 'SERIAL'),
'mms'=>array(
'type'=> 'INT',//note no size required
'null'=> TRUE),
'testing'=>array(
'type'=>'VARCHAR',
'constraint'=>'32',
'null'=>FALSE), );
$this->dbforge->add_field($fields);
$this->dbforge->create_table('phil');
If ($this->db->table_exists('phil'))
{
echo "<br/>";
echo "created table named phil";
// not working on first pass
// ie . if no table at start
// table IS created but NOT (echo) reported here
// works ok, if table existed at start
}


}

}

?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB