Welcome Guest, Not a member yet? Register   Sign In
I'm getting "Call to undefined function where()"
#1

I searched google with "call to undefined where() function codeigniter -redirect -model -encrypt -set_value -method -link_tag -img -lang -newRandomPwd -base_url -form_open -site_url -curl_init" and looked at all 26 pages of hits returned by this search, but none of them concerned the where clause.

I'm using CodeIgniter version 3.0.6.
phpMyAdmin reports that I'm using MySQL with the following details:

MySQL:
  • Server: Localhost via UNIX socket

  • Server version: 5.5.52-0ubuntu0.12.04.1-log

  • Protocol version: 10

  • User: root@localhost

  • MySQL charset: UTF-8 Unicode (utf8)
Upgrading is not an option at this time.

It also reports these details about my web-server:
  • Apache

  • MySQL client version: 5.5.52

  • PHP extension: mysqli
The sql statement I'm using is:

Code:
$columnList = "first_name, last_name, CONCAT( TRIM( first_name ), ' ', TRIM( last_name ) ) AS 'first_last_name'";
$columnList = preg_replace( '/\s{2,}/', ' ', $columnList );   // Replace tabs, newlines, and multiple spaces with a single space.
$query = $this->db->select( $columnList )
                   ->from( 'events' )
                   ->join( 'users',   'events.user_id = users.id' )
                   ->join( 'artists', 'events.user_id = presenters.user_id' )
                  ->where( 'EXPORT_SET( eventStatus, "1", "0", "", 4 ) like "10_0"' )
                  ->where( 'LOCATE( CONCAT( " ", "' . searchTerm . '", " " ), ' .
                                   'UPPER( CONCAT( " ", TRIM( first_name ), " ", TRIM( last_name ), " " ) ) ) > 0' )
                    ->get()->result();

The intent of this query is to return information about events and presenters associated with the events in a results table shown on the same page where the user enters the searchTerm used above.  Additional query columns will be added at a later time.

This query is called by the client using Ajax, but instead of getting any results, the error call-back function is used and it shows:
 'Call to undefined function where()'.

Before coding the above statements, I created and successfully tested the SQL Select statement in the phpMyAdmin query tool.

I found an example using Google showing the usage pattern similar to that I'm using here in the where() function, i.e., an somewhat complex expression, but I don't know if this usage is valid.

So besides the where function issue, perhaps someone could please comment on how best to perform more complex where clauses that are beyond the basic where( "table.column_name", php_variable_name ).

Thanks,
Howard Brown
Reply
#2

(10-05-2016, 09:57 AM)howardb1 Wrote: So besides the where function issue, perhaps someone could please comment on how best to perform more complex where clauses that are beyond the basic where( "table.column_name", php_variable_name ).

Don't, just use query().
Reply
#3

(10-05-2016, 11:06 AM)Narf Wrote:
(10-05-2016, 09:57 AM)howardb1 Wrote: So besides the where function issue, perhaps someone could please comment on how best to perform more complex where clauses that are beyond the basic where( "table.column_name", php_variable_name ).

Don't, just use query().

So by that are you saying that I should just put the whole SQL Select statement, Joins, Where, Ands, Ors, Having, Sort, etc. all in there together, and not break them out as CI appears to want to you? I'm good with that, its more conventional when compared to other embedded SQL mechanisms, such as BDE and ODBC, on PCs.  If that's not what you're meaning, then would you explain some more?

Thnaks!
Reply
#4

(This post was last modified: 10-07-2016, 01:21 PM by howardb1. Edit Reason: Formatting. )

I haven't tried this yet, mainly because my site has been misbehaving in a very bad way:

I'm getting only getting empty strings responses back in the httpResponse.responseText member most of the day, and only a few times am I getting anything else, this in spite of the fact that I've not changed the way my page communicates with the server.  Really odd, is that when I was on the phone with my host provider about this, I suddenly started getting responses, but the tech-support guy at the host provider, looking at the same page I was on, wasn't getting only getting empty responses.

In an effort to track this problem down, I captured the headers, and noticed that I was getting a length of 22 when I do get data, but 20 when I don't.  I don't know what this means, but it does show something different.  There are no errors or status differences other than the 22 vs 20 length is indicated.

Anyway, back to the issue of this thread, in my query, now stuffed with the entire select statement into the select function, if I use ? as place holders for value substitution, will they be substituted or do I need to use some other preprocessing step before using the query command?

Also, I read somewhere that the substitution that MySQLi used versus PDO or other databases, was lacking with regards to security compared to those other databases.  Is this true?  Is there something that I need do to do to prevent 'hackers' from hijacking my SQL Select queries?

Thanks again
Reply
#5

(This post was last modified: 10-09-2016, 12:21 AM by howardb1.)

I change the statement from select( ... ) to query( ... ) as you suggested, and that worked for me, but only for a few minutes.  Now, I'm not getting anything.  I reduced the function in the controller to almost the bare minimum, as follows:

PHP Code:
public function getData() {

 
 $returnObject'query'        $this->db->query"select 'hi' AS 'message'" );
 
 $returnObject'error'        $this->db->error();
 
 $returnObject'SQLStatement' ] = $this->db->last_query();
 
 $this->output->set_content_type'json''utf-8' );
 
 $this->output->set_outputjson_encode$returnObject ) );



Here iis result that I get on the client when they are run:


Code:
httpRequest: XMLHttpRequest
 contentType:"application/json; charset=utf-8"
 onreadystatechange:handleHTTPRequestReady()
 readyState:4
 response: "{"query: { "conn_id": { "affected_rows":null, "client_info":null,
                                    "client_version":null, "connect_errno":null,
                                    "connect_error":null, "errno":null,
                                    "error":null, "field_count":null,
                                    "host_info":null, "info":null,
                                    "insert_id":null, "server_info":null,
                                    "server_version":null, "stat":null,
                                    "sqlstate":null, "protocol_version":null,
                                    "thread_id":null, "warning_count":null },
                       "result_id": { "current_field":null, "field_count":null,
                                      "lengths":null, "num_rows":null,
                                      "type":null },
                       "result_array":[],
                       "result_object":[],
                       "custom_result_object":[],
                       "current_row":0,
                       "num_rows":null,
                       "row_data":null },
             "error":{ "code":0, "message":"" },
             "SQLStatement":"select 'hi' AS 'message'" }
 responseText: "{ "query": { "conn_id": { "affected_rows":null, "client_info":null,
                                          "client_version":null, "connect_errno":null,
                                          "connect_error":null, "errno":null,
                                           "error":null, "field_count":null,
                                          "host_info":null, "info":null,
                                          "insert_id":null, "server_info":null,
                                          "server_version":null, "stat":null,
                                          "sqlstate":null,"protocol_version":null,
                                        "thread_id":null, "warning_count":null },
                              "result_id"{ "current_field":null, "field_count":null,
                                          "lengths":null, "num_rows":null,
                                          "type":null },
                              "result_array":[],
                             "result_object":[],
                             "custom_result_object":[],
                             "current_row":0,
                             "num_rows":null,
                             "row_data":null },
                   "error":{"code":0,"message":""},
                   "SQLStatement":"select 'hi' AS 'message'"}"
 responseType:""
 responseURL:"http://...../Page/getData"
 responseXML:null
 status:200
 statusText:"OK"
 timeout:0
 upload:XMLHttpRequestUpload
 withCredentials:false

Of all of the information above, I think these are the most important things:


Code:
 result_array:[]                          -- Isn't this where the results of my query should be seen?
 num_rows:null                            -- Shouldn't this be something other than null?
 error:{"code":0,"message":""}            -- No error shown here.
 SQLStatement:"select 'hi' AS 'message'"  -- This is the query I'm trying run.

I talked with my hosting service, and in their logs they were able to track the request starting in the webpage in my browser go to the web-server, then on to the database server, and back to the web-server, but the data never gets sent back to my browser.

Since it is the first line of the function that actually sends the request to the database server and then receives the results, I don't know of anyway to go any farther in solving this issue.  The other thing is all of the other queries handled different functions in the same controller work fine.

My call to the hosting service ended with "It's in your code, we don't debug code."  So, I'm stuck.

Anyone out there seen or know how I can solve this issue?

Thanks
Reply
#6

(This post was last modified: 10-09-2016, 02:56 PM by cartalot.)

I don't know your experience level - but you are doing some very complicated database calls - and it sounds like you are not certain about your server.

So what i would suggest is to do some step by step sanity checks - do some pages and models where you are doing much simpler database calls. Make sure that all works on your server. If there are still issues then just get another host because PHP hosting is really cheap especially compared to your time.

Otherwise if its not the server then build up some of your functionality with some simpler models and db calls. And seek out codeigniter tutorials and libraries so you can increase your knowledge. Then go for the more complicated queries.
Reply
#7

(10-07-2016, 01:02 PM)howardb1 Wrote:
(10-05-2016, 11:06 AM)Narf Wrote:
(10-05-2016, 09:57 AM)howardb1 Wrote: So besides the where function issue, perhaps someone could please comment on how best to perform more complex where clauses that are beyond the basic where( "table.column_name", php_variable_name ).

Don't, just use query().

So by that are you saying that I should just put the whole SQL Select statement, Joins, Where, Ands, Ors, Having, Sort, etc. all in there together, and not break them out as CI appears to want to you?

CI doesn't want you to do this.

It gives you the option of doing it and in your case I don't see how you'd benefit from that. Don't use stuff just because it's there, use it if you need it.

(10-07-2016, 01:19 PM)howardb1 Wrote: if I use ? as place holders for value substitution, will they be substituted or do I need to use some other preprocessing step before using the query command?

You don't need to do any extra work.

(10-07-2016, 01:19 PM)howardb1 Wrote: Also, I read somewhere that the substitution that MySQLi used versus PDO or other databases, was lacking with regards to security compared to those other databases.  Is this true?  Is there something that I need do to do to prevent 'hackers' from hijacking my SQL Select queries?

That's completely untrue.
And it wouldn't matter anyway.

PDO is just easier to work with if you are using it directly, which isn't the case here - you're using a framework that abstracts all those little details away from you.

(10-09-2016, 12:02 AM)howardb1 Wrote: Of all of the information above, I think these are the most important things:

Code:
 result_array:[]                          -- Isn't this where the results of my query should be seen?
 num_rows:null                            -- Shouldn't this be something other than null?
 error:{"code":0,"message":""}            -- No error shown here.
 SQLStatement:"select 'hi' AS 'message'"  -- This is the query I'm trying run.

result_array won't be populated until you call result_array()
Similarly, num_rows() won't be populated until you call num_rows()

Nothing out of ordinary here.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB