CodeIgniter Forums
SQL Server Not Returning Data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: SQL Server Not Returning Data (/showthread.php?tid=62102)



SQL Server Not Returning Data - bazianm - 06-09-2015

Hi,

I have a model that has a simple query. Here's the code:

PHP Code:
$this->db->select("*")
 ->
from("vmb_TempsAndTolerances")
 ->
where("idgrades"$idgrade)
 ->
where("idtypes"$idtype);
 
 
$query $this->db->get();
 
$result_array $query->result_array

I have profile turned on and this is the query that is generated by this:

Code:
SELECT *
FROM vmb_TempsAndTolerances
WHERE idgrades =  'C19B5EC2-FBCB-4761-9ACE-43297F0876B7'
AND idtypes =  'BFB30716-EA84-4E34-9A81-1A07EAF37AD5'  

When I copy this into SQL Server Management Studio, I get information returned. Yet, $result_array is coming back empty.

I var_dumped both $query and $result_array and here is what I get from that.

Code:
object(CI_DB_sqlsrv_result)[16]
 public 'conn_id' => resource(29, SQL Server Connection)
 public 'result_id' => resource(39, SQL Server Statement)
 public 'result_array' =>
   array (size=0)
     empty
 public 'result_object' =>
   array (size=0)
     empty
 public 'custom_result_object' =>
   array (size=0)
     empty
 public 'current_row' => int 0
 public 'num_rows' => int 4
 public 'row_data' => null

array (size=0)
 empty

No errors are returned. I have many other queries that work just fine.

Any ideas at this point are appreciated.

Thanks


RE: SQL Server Not Returning Data - mwhitney - 06-09-2015

Did you try $query->result_array() instead of $query->result_array?

Do you have autoinit set to true in your database config (or, if not, are you initializing your database connection)?


RE: SQL Server Not Returning Data - Blair2004 - 06-09-2015

Actually result_array it's a method and not a property


RE: SQL Server Not Returning Data - bazianm - 06-09-2015

(06-09-2015, 12:26 PM)mwhitney Wrote: Did you try $query->result_array() instead of $query->result_array?

Do you have autoinit set to true in your database config (or, if not, are you initializing your database connection)?

It was result_array(). Don't ask me how I missed that. I must have looked at that piece of code 1000 times!

I wonder why PHP didn't kick that out as an error?

THANKS for the assist!


RE: SQL Server Not Returning Data - mwhitney - 06-10-2015

(06-09-2015, 02:14 PM)bazianm Wrote:
(06-09-2015, 12:26 PM)mwhitney Wrote: Did you try $query->result_array() instead of $query->result_array?

Do you have autoinit set to true in your database config (or, if not, are you initializing your database connection)?

It was result_array(). Don't ask me how I missed that. I must have looked at that piece of code 1000 times!

I wonder why PHP didn't kick that out as an error?

THANKS for the assist!

result_array is also a public property in the db library, but it doesn't necessarily have a value until you call one of the methods which populates it (like result_array()).


RE: SQL Server Not Returning Data - bazianm - 06-10-2015

(06-10-2015, 06:32 AM)mwhitney Wrote:
(06-09-2015, 02:14 PM)bazianm Wrote:
(06-09-2015, 12:26 PM)mwhitney Wrote: Did you try $query->result_array() instead of $query->result_array?

Do you have autoinit set to true in your database config (or, if not, are you initializing your database connection)?

It was result_array(). Don't ask me how I missed that. I must have looked at that piece of code 1000 times!

I wonder why PHP didn't kick that out as an error?

THANKS for the assist!

result_array is also a public property in the db library, but it doesn't necessarily have a value until you call one of the methods which populates it (like result_array()).

Oh OUCH! That's an error I will try not to make again. Cost me the better part of a day and a half of time.

Thanks!


RE: SQL Server Not Returning Data - lexxtoronto - 06-12-2015

>>I wonder why PHP didn't kick that out as an error?

Is it in production mode? Errors will be suppressed. I also had a similar problem with db queries and it won't show any errors, but then I realized they were db generated errors and I wasnt catching them.


RE: SQL Server Not Returning Data - Blair2004 - 06-13-2015

4 rows seems to be returned, use result_array() instead, since $result_array is empty