Can not get field_data by $query->field_data(); #1619

Closed
sdhiraj opened this Issue Jul 14, 2012 · 5 comments

Projects

None yet

4 participants

@sdhiraj
sdhiraj commented Jul 14, 2012

$query = $this->db->query("YOUR QUERY");
$fields = $query->field_data();

In Codeigniter 2.1.2 When executing this type of query it gives following errors
(it works fine in 2.1.0)

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Type

Filename: mysql/mysql_result.php

Line Number: 89
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Field

Filename: mysql/mysql_result.php

Line Number: 95
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Default

Filename: mysql/mysql_result.php

Line Number: 97
A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$Key

Filename: mysql/mysql_result.php

Line Number: 99

@appleboy

You must set one parameter for table name.

$fields = $query->field_data('test');
@ghost
ghost commented Jul 19, 2012

Use build in CI function to get field names. Why need to write SQL.

$fields = $this->db->list_fields('table_name');

@HipsterJazzbo

This is still quite obviously and thoroughly broken. In 2.1.2 field_data() is using mysqli_fetch_object, which seems completely wrong as that method returns the row itself, not data about it. Not sure of when this could ever work.

There are several related issues that have been closed (#1111, #785, #1101), but the attached commits don't seem to work - they fix the field_data() call on a query result object, but break $this->db->field_data() in the sense that it now returns different results (i.e. fields types are strings instead of numerical).

@appleboy You only need to pass in the table name when calling $this->db->field_data($table). When calling field_data() on a query result object, you don't need the table name.

@goserverside Again, @sdhiraj is talking specifically about calling field_data() on a query result object.

This is stinging me hard at the moment, so just wanted to add some more detail and make sure this issue doesn't get ignored. If I manage to fix it before I run out of time and have to abandon the upgrade, I'll submit a pull request.

@HipsterJazzbo

I should have said, I can see that this SEEMS to be fixed in 3.0-dev, although I haven't tested.

@narfbg
Collaborator
narfbg commented Nov 15, 2012

It is indeed fixed in develop.

@narfbg narfbg closed this Nov 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment