Eduardo Fuerte
asked on
Could you point why this Codeigniter's data insertion is causing an error?
Hi Experts
Could you point why this Codeigniter's data insertion is causing an error?
Thanks in advance!
The $params array:
The MySQL table structure where the data must to be inserted:
Could you point why this Codeigniter's data insertion is causing an error?
if ($this->db->insert("server_routes", $params)) {
return $this->db->insert_id();
} else {
return false;
}
Thanks in advance!
The $params array:
array(9) { ["id"]=> string(0) "" ["_name"]=> string(3) "xxx" ["_hostname"]=> string(14) "192.168.100.76" ["_port"]=> string(4) "5060" ["_providerId"]=> string(2) "13" ["_prefix"]=> string(5) "65019" ["_active"]=> string(1) "1" ["_channel"]=> string(3) "120" ["_description"]=> string(0) "" }
The MySQL table structure where the data must to be inserted:
CREATE TABLE server_routes (
id int(11) NOT NULL DEFAULT 0,
_name varchar(150) DEFAULT NULL,
_hostname varchar(45) DEFAULT NULL,
_port int(11) DEFAULT NULL,
_providerId int(11) DEFAULT NULL,
_prefix varchar(15) DEFAULT NULL,
_active int(11) DEFAULT NULL,
_channel int(11) DEFAULT 30,
_description text DEFAULT NULL
)
ENGINE = INNODB
AVG_ROW_LENGTH = 327
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try omitting (removing) the "id" from the $params array. See what happens and let us know, thanks.
ASKER
@Ray
Yes, this way of sending data for insertions is accepted to Codeigniter.
Yes, this way of sending data for insertions is accepted to Codeigniter.
ASKER
Thank you for the help!
Just curious - what fixed the issue?
ASKER
Of course.
Just to apply PK to id column and make it Auto Increment.
After that the initial code perfectly runs under Codeigniter.
Just to apply PK to id column and make it Auto Increment.
After that the initial code perfectly runs under Codeigniter.
Full disclosure: I don't know much about CodeIgniter, and these frameworks have their own conventions, so maybe this is acceptable in the CodeIgniter world. It just seems odd to me, based on my experience with PHP and MySQL.