Codeigniter query doesn't run even though it runs on the server - php

I have a query made by codeigniter's query builder.
Up until recently, the query was working fine.
Now, it gives us a blank page but I've made no changes to it.
I turned error reporting on and it gave the generic query of it didn't return any results
Call to a member function result() on a non-object in /application/models/order_model.php on line 311
I dumped the query and tried to run on the server itself, it works.
Is there anything else I can try to debug it?

Related

Codeigniter - query does not execute from a specific controller

I face this problem:
I have a function in a Model which runs a select query: I call it from the controller A (not real name). When I call the same method, but from the controller B, the PHP script stops when the query executes.
This function receives a number or an array as parameter. I've set the value of the parameter within the model to be sure I don't send wrong data from the controller B, and it keeps happening.
The query:
$arrConversas = $this->db->where_in('codigo_conversa', $codigo_conversa)
->group_by(['codigo_origem','codigo_destino',
'tipo_origem', 'tipo_destino'])
->get('conversa_mensagem')->result();
I think the code isn't wrong because it runs normally from controller A.
What am I doing wrong?
EDIT:
Thank you guys. The problem was a procedure that was running before this query, I tried to flush the connection and clean the cache and the problemas was there yet, then I use a $this->db->reconnect(); . Not the best solution but this action won't be used everyday.
I saw on the debugging the error: "Commands out of sync; you can't run this command now".
Thanks again!
I think you did not write the $this->load->database(); in your constructor in the model.
The problem was a procedure that was running before this query, then I used $this->db->reconnect(); and it worked !

Can't load main website or the Magento /admin page. Just loads as a blank page! Error log provided

Our site has been down since I tried doing a backup of our Magento site. This was the last thing I did that could have triggered something. I had made other changes throughout the day, but only playing with some extensions, and this was a couple hours prior to the error. Below is the last entry to the error log:
[16-Jun-2015 18:42:56 UTC] PHP Fatal error: Call to a member function
setLayer() on a non-object in
**public_html/app/code/core/Mage/Catalog/Block/Layer/View.php on line 134
Got into the line its calling to but have no idea what to do with it! Not even sure if this is the direct cause of this issue. I feel something should still load.
Could it be something simple I'm missing like a Maintenance flag?
Any other reasons why the site could be behaving like this? Quite frustrating that I cant even reach the admin page. All our other subdomain site work too.
It would appear to me that somewhere in your coding of some extensions you broke something. This error happens when you have what you think is an object but is actually not and you call a method on it.
for instance if you have something like the following
<?php
$obj = function_to_get_object('name');
$obj->getName();
if the function_to_get_object does not return an object but rather returns NULL or false then calling the method getName will fail because the variable is not an object rather NULL or FALSE.
I could not see this happening with a Magento install (without custom code) unless maybe you deleted a file or something and the base install cannot find the file to include or instantiate the object.

Can’t get the phpunit core test for WordPress to work

I’m trying to set up the test for the WordPress core to make sure that the plugin I’m developing dose’t break anything. But I’m having a problem which I really have no idea how to fix. I downloaded the files located at www.develop.svn.wordpress.org/trunc(I know I can use sub-version, but I’m having some troubles setting it up in phpStorm, so I’m focusing on this problem), and set everything up.
I get the tests running, but about half way through the tests, I get an error, which i have no idea where originates. It’s to long to post here, but it seems to repeate it self, so here is a a sample of the first lines
WordPress database error Table 'multipress_testc.wptests_4_options' doesn't exist for
query INSERT INTO `wptests_4_options` (`option_name`, `option_value`, `autoload`) VALUES
('active_plugins', 'a:1:{i:0;s:9:\"hello.php\";}', 'yes') ON DUPLICATE KEY UPDATE
`option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload`
= VALUES(`autoload`) made by PHPUnit_TextUI_Command::main, PHPUnit_TextUI_Command->run,
PHPUnit_TextUI_TestRunner->doRun, PHPUnit_Framework_TestSuite->run,
PHPUnit_Framework_TestSuite->run, PHPUnit_Framework_TestSuite->runTest,
PHPUnit_Framework_TestCase->run, PHPUnit_Framework_TestResult->run,
PHPUnit_Framework_TestCase->runBare, PHPUnit_Framework_TestCase->runTest,
ReflectionMethod->invokeArgs, Tests_MS->test_active_network_plugins, activate_plugin,
update_option, add_option
The last errors i get is a php errors saying
PHP Fatal error: Call to a member function to_array() on a non-object in /Applications/MAMP/htdocs/(folder-name)/(wordpress root folder)/wp-includes/post.php on line 411
Fatal error: Call to a member function to_array() on a non-object in /Applications/MAMP/htdocs/(folder-name)/(wordpress root folder)/wp-includes/post.php on line 411
The value of the non-object is bool(false)
I’m running the multisite tests.

CodeIgniter with a PostgreSQL multiple schemas issue

I am developing an agent-port application in CodeIgniter with PostgreSQL by using mutiple schemas from a single database. The setup I have designed is working fine.
So the problem I am facing right now is when after some interval it starts showing the following errors on different pages, like:
Fatal error: Call to a member function result() on a non-object in
D:\xampp\htdocs\mangonet\application\modules\settings\models\adminmodel.php
on line 30
Fatal error: Call to a member function num_rows() on a non-object in
D:\xampp\htdocs\mangonet\application\modules\users\models\adminmodel.php
on line 56
Fatal error: Call to a member function row() on a non-object in
D:\xampp\htdocs\mangonet\application\modules\users\models\adminmodel.php
on line 86
Let me give one example
I try to find out a particular problem only if it always remains there. But when I refresh my page or remove that row() from the function
function get_item_by_id($table, $id)
{
return $this->db->get_where($table, array('id' => $id))->row();
}
it returns a black result and when I add it back, the problem gone, and it starts working fine.
I know the above fatal errors you can see above solutions are available. But my problem is a bit complex.
This sounds like a problem with database connections going away. I would recommend looking at debugging this on the application side. In particular I would start logging the following:
Database connection status on all problematic calls. In other words check and see if the database connection has closed or failed.
If the database connection has not failed, then the next thing to check is what the search path is. You can execute the following query to test it:
SHOW search_path;
It is possible that if this is related to multiple schemas, something is messing with that.

Codeigniter DB errors after stored procedure call

I have a database that has a few stored procedures in it that I would like to call via CodeIgniter. I have the following code in my Model class:
$sql = "CALL `stored_proc`(1)";
$query = $this->db->query($sql); //This call breaks the DB :(
$this->db->select('status');
$this->db->where('id', $id);
$query = $this->db->get('table');
print($query->num_rows()); //line 1116
When I run this code, I get the following error:
Fatal error: Call to a member function num_rows() on a non-object in C:\server\apache\htdocs\application\models\let_model.php on line 1116
If I remove the query line, the select works properly. Also, if I replace the call to a stored procedure with say a SELECT command, it also works properly.
Is there something obvious I'm missing for why I'm getting this error? If there isn't a good answer, is there a way to work around this problem?
Thanks for your time!
Edit: After delving a little deeper into the problem, it seems that this error will occur if my stored procedure contains a SELECT command. UPDATES seem to work properly. Perhaps this problem has something to do with how CodeIgniter deals with SELECT results?
Since this question appears first on google, i've managed to solve this by using :
$this->db->simple_query($query);
Instead of the regular query function.
The problem was that the SELECTs in the stored procedure were causing problems in CodeIgniter. By making sure that all of the SELECTs were directed (i.e. with the INTO clause), the stored procedure was able to run successfully.
For example,
-- This causes an error in CodeIgniter when inside a stored procedure.
SELECT GET_LOCK('lock1',0);
-- This does not.
DECLARE _lock_result INT;
SELECT GET_LOCK('lock1',0) INTO _lock_result;
I am still unaware of the underlying causes of why this causes an error, but this solution will suffice for my current work.
use only
$query->num_rows instead of $query->num_rows()

Categories