Tuesday 15 July 2014

php - PDO Statement Fetch - Cannot access empty property -


I'm really confused here.

This query works perfectly fine on the local host, but no other actual live server has any other questions on the job of the same database, so there is nothing wrong with connection or PDO extensions.

Actually this query is:

  $ sql = "SELECT * Bksb_Resources"; $ Query = $ this- & gt; Connection- & gt; Query ($ sql, array ());   

The query () method returns the PDOStatement object

Then I type $ this-> Connection- & gt; Fetch ($ query) in a loop, which in turn is sent to a method on the "Connection" object:

  function fetch_pdo ($ st) {return $ st - & gt; Fetch (); }   

So basically it is selecting all from one table and then returning the first row (this is a loop but it is not really relevant).

On the local host, this is fine. No problem at all.

Fatal error: / var / www / html / demo / blocks / elbp / classes / / 652

/ Pre>

Line 652 is returned with the fetch_pdo method, where the DB / MSSQL.Clas.FPP.

I have printed the statement before running it, fetch () and it is okay on both servers:

  PDOsetment object ([query string] = & gt; SELECT * FROM bksb_Resources) I am out of ideas I can not see why it will work on one server and not the other, when the rest of the questions also work well on the live server.  

(Well ... I say the rest, this is basically a different problem where the query returned the right result at the local host and did not return anything to the query on the live, even if I had to go to the management studio The copy / paste query worked fine but I have tried to debug

thanks

edit:

$ Call this- & gt; connection- & gt; query ($ sql, array ());

calls it:

  / ** * A Run the C-SQL query and things like choosing a statement - * Ultimate Type $ SQL * @ PAM Type $ param * * Return Type * / Public Function Query ($ sql, $ params) * $ $ -> Last SQL = $ sql $ Func = 'query_'. $ This-> Extension; $ The-> $ func ($ sql, $ params);}   

Then it calls:

  / ** * Run SQL query using PDO * @ PRM type $ sql * @ PRAM type $ params * @ return $ cent state T * / private function query_pdo ($ sql, $ params) {$ st = $ this- & gt; Dbh- & gt; Ready ($ sql); $ St- & gt; Execution ($ parameter); Return $ cents; }   

And if you want it too, then this is the loop where I'm saying fetch:

  $ results = array (); While ($ line = $ this-> Connection-> Fetch ($ query)) {$ result [] = $ line; I am facing this error recently with a PDO and a MySQL backend.    

This was due to the fact that my query returned a column with an empty nickname The following queries were made:

  From selector names, "" from users;   

This is a completely valid query (in this period that MySQL will fully interpret and execute it), but it can not use an "Empty Property" Fatal Error , When the PDO attempts to get the data and FetchMode is set to PDO :: FETCH_OBJ.

It should be given to anyone with the same problem, to decide how to fix it. At some point, PDO will instantiate an STD class and will attempt to set a property for each column returned by the query. When a column is returned with an empty name, then the PDO will basically execute the following code:

  // $ obj a stdClass example $ prop = ''; // query column $ obj- & gt; $ Prop = $ value name; // value of the query column   

This "can not use empty property" leads to fatal error.

No comments:

Post a Comment