Welcome Guest, Not a member yet? Register   Sign In
Problem/Error with DB Forge table creation.
#1

[eluser]Hickeroar[/eluser]
Code:
$this->dbforge->add_field("`app_id` int(11) NOT NULL auto_increment");
            $this->dbforge->add_field("`app_name` varchar(45) NOT NULL default ''");
            $this->dbforge->add_key('app_id', TRUE);
            $this->dbforge->create_table('apps', TRUE);


If I remove lines 1 & 3, it works. Creates the apps table and puts in the app_name field. If I remove just line 3, obviously it dies because you have to define the auto-increment field as a primary key. if I leave it as-is, it gives me this:


Quote:A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_driver.php

Line Number: 1206


A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_driver.php

Line Number: 1215


A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_driver.php

Line Number: 1291


A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: mysql/mysql_driver.php

Line Number: 438


A PHP Error was encountered

Severity: Warning

Message: implode(): Bad arguments.

Filename: mysql/mysql_forge.php

Line Number: 158


A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' at line 4

CREATE TABLE IF NOT EXISTS `apps` ( app_id int(11) NOT NULL auto_increment, `app_name` varchar(45) NOT NULL default '', PRIMARY KEY `app_id` () ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Is this a bug in DB Forge?

DB is MySQL 4.X
#2

[eluser]cbosuna[/eluser]
I found the problem and here is a patch, can someone on the CodeIgniter team please apply?

--- a/system/database/drivers/mysql/mysql_forge.php
+++ b/system/database/drivers/mysql/mysql_forge.php
@@ -154,8 +154,8 @@ class CI_DB_mysql_forge extends CI_DB_forge {
if (count($primary_keys) > 0)
{
$key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
- $primary_keys = $this->db->_protect_identifiers($primary_keys);
- $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
+ $primary_keys = $this->db->_protect_identifiers(implode(', ', $primary_keys));
+ $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . $primary_keys . ")";
}

if (is_array($keys) && count($keys) > 0)
#3

[eluser]sl3dg3hamm3r[/eluser]
If you think it is a bug, maybe you should post it in the bug-section...
#4

[eluser]cbosuna[/eluser]
I did. Was not familiar with CI community policy.
#5

[eluser]Hickeroar[/eluser]
Thanks friend. Smile Worked like a charm. I guess DBForge isn't used too much for table creation? Strange that something like this got missed.




Theme © iAndrew 2016 - Forum software by © MyBB