yii2 select column from relation table trouble - yii2

i want choose all devlopers table data , with only "username" column in User table
i write this but i get error
$model = Developers::find()->select('*')->with(['users' => function($q){
$q->select('username');
}])->asArray()->all();
my Developers "developer_id" column have relation with User table id column
so in Developers model i wrote
public function getUsers()
{
return $this->hasOne(User::className(), ['id' => 'developer_id']);
}
error is
PHP Notice 'yii\base\ErrorException' with message 'Undefined index: id'
in /srv/http/adone/vendor/yiisoft/yii2/db/ActiveRelationTrait.php:501
Stack trace:
#0 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveRelationTrait.php(501): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/srv/http/adone...', 501, Array)
#1 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveRelationTrait.php(381): yii\db\ActiveQuery->getModelKey(Array, Array)
#2 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveRelationTrait.php(245): yii\db\ActiveQuery->buildBuckets(Array, Array)
#3 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveQueryTrait.php(174): yii\db\ActiveQuery->populateRelation('users', Array)
#4 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveQuery.php(214): yii\db\ActiveQuery->findWith(Array, Array)
#5 /srv/http/adone/vendor/yiisoft/yii2/db/Query.php(214): yii\db\ActiveQuery->populate(Array)
#6 /srv/http/adone/vendor/yiisoft/yii2/db/ActiveQuery.php(135): yii\db\Query->all(NULL)
#7 /srv/http/adone/controllers/admin/SiteAdminController.php(30): yii\db\ActiveQuery->all()
#8 [internal function]: app\controllers\admin\SiteAdminController->actionViewDevelopers()
#9 /srv/http/adone/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#10 /srv/http/adone/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#11 /srv/http/adone/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction('view-developers', Array)
#12 /srv/http/adone/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction('admin/site-admi...', Array)
#13 /srv/http/adone/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#14 /srv/http/adone/web/index.php(12): yii\base\Application->run()
#15 {main}
why this happened?

Try this:
Developers::find()->select('developers.*, user.username')->joinWith(['users'])->asArray()->all()

Related

yii2 - An Error occurred while handling another error:

I am trying to implement Metronic Theme to my Yii-2 advanced application's backend. I followed the instructions on GitHub step by step, however I keep getting a blank page with the following error on it. I am truly stuck.
Here is the error:
An Error occurred while handling another error:
Error: Call to undefined method yii\base\ErrorException::getSeverity() in
C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\ErrorHandler.php:287
Stack trace:
#0 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\ErrorHandler.php(107):
yii\base\ErrorHandler->logException(Object(yii\base\ErrorException))
#1 [internal function]: yii\base\ErrorHandler-
>handleException(Object(yii\base\ErrorException))
#2 {main}
Previous exception:
yii\base\ErrorException: Illegal string offset 'id' in
C:\xampp\htdocs\advanced\vendor\dlds\yii2-metronic\widgets\NavBar.php:59
Stack trace:
#0 C:\xampp\htdocs\advanced\vendor\dlds\yii2-
metronic\widgets\NavBar.php(59): yii\base\ErrorHandler->handleError(2,
'Illegal string ...', 'C:\\xampp\\htdocs...', 59, Array)
#1 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Object.php(107):
dlds\metronic\widgets\NavBar->init()
#2 [internal function]: yii\base\Object->__construct(Array)
#3 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\di\Container.php(381):
ReflectionClass->newInstanceArgs(Array)
#4 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\di\Container.php(156):
yii\di\Container->build('dlds\\metronic\\w...', Array, Array)
#5 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\BaseYii.php(348):
yii\di\Container->get('dlds\\metronic\\w...', Array, Array)
#6 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Widget.php(89):
yii\BaseYii::createObject(Array)
#7 C:\xampp\htdocs\advanced\backend\views\layouts\main.php(47):
yii\base\Widget::begin(Array)
#8 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\View.php(330):
require('C:\\xampp\\htdocs...')
#9 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\View.php(250):
yii\base\View->renderPhpFile('C:\\xampp\\htdocs...', Array)
#10 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(396):
yii\base\View->renderFile('C:\\xampp\\htdocs...', Array,
Object(dektrium\user\controllers\SecurityController))
#11 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(382):
yii\base\Controller->renderContent('\n\n <div clas...')
#12 C:\xampp\htdocs\advanced\vendor\dektrium\yii2-
user\controllers\SecurityController.php(166): yii\base\Controller-
>render('login', Array)
#13 [internal function]: dektrium\user\controllers\SecurityController-
>actionLogin()
#14 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\InlineAction.php(57):
call_user_func_array(Array, Array)
#15 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Controller.php(156):
yii\base\InlineAction->runWithParams(Array)
#16 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Module.php(523):
yii\base\Controller->runAction('login', Array)
#17 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\web\Application.php(102):
yii\base\Module->runAction('user/security/l...', Array)
#18 C:\xampp\htdocs\advanced\vendor\yiisoft\yii2\base\Application.php(380):
yii\web\Application->handleRequest(Object(yii\web\Request))
#19 C:\xampp\htdocs\advanced\admin\index.php(15): yii\base\Application-
>run()
#20 {main}
You must add 'error' on actions
'rules' => [
[
'actions' => ['error', ...

Yii2 migration configException error

Suddenly any of the migration command is not working in my project and i don't know why. following is the errors in cmd.
C:\wamp64\www\project>yii migrate
Exception 'yii\base\InvalidConfigException' with message 'Failed to instantiate component or class "user".'
in C:\wamp64\www\project\vendor\yiisoft\yii2\di\Instance.php:139
Stack trace:
#0 C:\wamp64\www\project\vendor\yiisoft\yii2\filters\AccessControl.php(100): yii\di\Instance::ensure(Object(yii\di\Instance), 'yii\\web\\User')
#1 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Object.php(107): yii\filters\AccessControl->init()
#2 [internal function]: yii\base\Object->__construct(Array)
#3 C:\wamp64\www\project\vendor\yiisoft\yii2\di\Container.php(381): ReflectionClass->newInstanceArgs(Array)
#4 C:\wamp64\www\project\vendor\yiisoft\yii2\di\Container.php(156): yii\di\Container->build('yii\\filters\\Acc...', Array, Array)
#5 C:\wamp64\www\project\vendor\yiisoft\yii2\BaseYii.php(348): yii\di\Container->get('yii\\filters\\Acc...', Array, Array)
#6 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Component.php(183): yii\BaseYii::createObject(Array)
#7 C:\wamp64\www\project\vendor\yiisoft\yii2\BaseYii.php(529): yii\base\Component->__set('beforeRequest', Array)
#8 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Object.php(105): yii\BaseYii::configure(Object(yii\console\Application), Array)
#9 C:\wamp64\www\project\vendor\yiisoft\yii2\base\Application.php(205): yii\base\Object->__construct(Array)
#10 C:\wamp64\www\project\vendor\yiisoft\yii2\console\Application.php(89): yii\base\Application->__construct(Array)
#11 C:\wamp64\www\project\yii(26): yii\console\Application->__construct(Array)
#12 {main}
Please help me to solve it.

CakePHP and Phinx addForeignKey fails, duplicate column

I'm trying to create a migration to add a foreign key to an existing column, it looks like this:
use Migrations\AbstractMigration;
class AddForeignKeyIndexToPoints extends AbstractMigration
{
public function up()
{
$this->table('points')
->addForeignKey('point_type_id', 'point_types', ['id'])
->save();
}
public function down() {
}
}
which fails like this:
== 20170202112138 AddPointTypeToPoints: migrating
Exception: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'point_type_id' in [C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php, line 306]
2017-02-03 11:12:01 Error: [PDOException] SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'point_type_id'
Stack Trace:
#0 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\PdoAdapter.php(306): PDO->exec('ALTER TABLE `po...')
#1 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Adapter\MysqlAdapter.php(408): Phinx\Db\Adapter\PdoAdapter->execute('ALTER TABLE `po...')
#2 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\CakeAdapter.php(480): Phinx\Db\Adapter\MysqlAdapter->addColumn(Object(Migrations\Table), Object(Phinx\Db\Table\Column))
#3 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Table.php(625): Migrations\CakeAdapter->addColumn(Object(Migrations\Table), Object(Phinx\Db\Table\Column))
#4 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Table.php(81): Phinx\Db\Table->update()
#5 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Db\Table.php(662): Migrations\Table->update()
#6 C:\Users\Toby\Documents\projects\map\cake\config\Migrations\20170202112138_AddPointTypeToPoints.php(17): Phinx\Db\Table->save()
#7 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager\Environment.php(117): AddPointTypeToPoints->up()
#8 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php(309): Phinx\Migration\Manager\Environment->executeMigration(Object(AddPointTypeToPoints), 'up')
#9 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php(285): Phinx\Migration\Manager->executeMigration('default',Object(AddPointTypeToPoints), 'up')
#10 C:\Users\Toby\Documents\projects\map\cake\vendor\robmorgan\phinx\src\Phinx\Console\Command\Migrate.php(113): Phinx\Migration\Manager->migrate('default', NULL)
#11 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\ConfigurationTrait.php(165): Phinx\Console\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Command\Migrate.php(58): Migrations\Command\Migrate->parentExecute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Command\Command.php(255): Migrations\Command\Migrate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(829): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(191): Symfony\Component\Console\Application->doRunCommand(Object(Migrations\Command\Migrate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 C:\Users\Toby\Documents\projects\map\cake\vendor\symfony\console\Application.php(122): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Shell\MigrationsShell.php(98): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
#18 [internal function]: Migrations\Shell\MigrationsShell->main('migrations', 'migrate')
#19 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\Shell.php(466): call_user_func_array(Array, Array)
#20 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\migrations\src\Shell\MigrationsShell.php(130): Cake\Console\Shell->runCommand(Array, true, Array)
#21 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(227): Migrations\Shell\MigrationsShell->runCommand(Array,true, Array)
#22 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(182): Cake\Console\ShellDispatcher->_dispatch(Array)
#23 C:\Users\Toby\Documents\projects\map\cake\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php(128): Cake\Console\ShellDispatcher->dispatch(Array)
#24 C:\Users\Toby\Documents\projects\map\cake\bin\cake.php(34): Cake\Console\ShellDispatcher::run(Array)
#25 {main}
There's at least one example in the Phinx docs that leads me to believe this should work, but I can't get it to - what am I doing wrong?

Laravel MySQL Error ONLY on Scheduled Tasks (via cron)

I have a task using the Laravel task scheduler than fires perfectly.
It fires to call a public method named Task::checkSpiders().
This hits an API (works fine) then should update local DB accordingly.
If i create a route as so...
Route::get('/test', function () {
$test = Task::checkSpiders();
}
It run's perfectly.
When i run it from CRON however it throws me this error...
#0 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(55): PDO->__construct('mysql:host=loca...', 'forge', '', Array)
#1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=loca...', Array, Array)
#2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(61): Illuminate\Database\Connectors\MySqlConnector->connect(Array)
#3 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}()
#4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(920): call_user_func(Object(Closure))
#5 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(788): Illuminate\Database\Connection->getPdo()
#6 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(673): Illuminate\Database\Connection->reconnectIfMissingConnection()
#7 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(479): Illuminate\Database\Connection->run('update `tasks` ...', Array, Object(Closure))
#8 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(422): Illuminate\Database\Connection->affectingStatement('update `tasks` ...', Array)
#9 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2072): Illuminate\Database\Connection->update('update `tasks` ...', Array)
#10 /var/www/laravel/app/Task.php(60): Illuminate\Database\Query\Builder->update(Array)
#11 /var/www/laravel/app/Task.php(85): App\Task::updateTask('a5b829767a6811e...', 'Finished', '2016-09-14 10:4...', '2016-09-14 11:5...')
#12 /var/www/laravel/app/Console/Kernel.php(34): App\Task::checkSpiders()
#13 [internal function]: App\Console\Kernel->App\Console\{closure}()
#14 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Object(Closure), Array)
#15 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php(61): Illuminate\Container\Container->call(Object(Closure), Array)
#16 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php(61): Illuminate\Console\Scheduling\CallbackEvent->run(Object(Reflexions\DockerLaravel\DockerApplication))
#17 [internal function]: Illuminate\Console\Scheduling\ScheduleRunCommand->fire()
#18 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#19 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#20 /var/www/laravel/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/laravel/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /var/www/laravel/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /var/www/laravel/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /var/www/laravel/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}
The code to insert to the DB ( I don't think is relevant but i'll add in anyway..)
$tasks = DB::table('tasks')
->where('id', $id)
->whereNull('end')
->update([
'status' => $status,
'start' => $start,
'end' => $end,
]);
Also, just a note I am running this in Docker using Supervisord to manage CRON with Laravel.
Any help much appreciated!
Stupid Mistake;
CRON is running under a different user thus the enviroment variables loading from .env aren't available.
I checked this by logging the ENV variables from a task run in CRON.
Like so...
Log::info(json_encode(get_defined_vars()));
That returned [] an empty array.
I've since hardcoded the variables to the config and all is working perfectly.
Alternatively I could have set the ENV Variables in PHP (Incase they are used elsewhere) using...
<?php
putenv("KEY=value");
?>

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away - What to do?

Here is what I get and I don't know what to do....
There has been an error processing your request
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
Trace:
#0 /home/autobadges/public_html/stangcenter.com/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/autobadges/public_html/stangcenter.com/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /home/autobadges/public_html/stangcenter.com/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `main_ta...', Array)
#3 /home/autobadges/public_html/stangcenter.com/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `main_ta...', Array)
#4 /home/autobadges/public_html/stangcenter.com/lib/Zend/Db/Adapter/Abstract.php(734): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
#5 /home/autobadges/public_html/stangcenter.com/lib/Varien/Data/Collection/Db.php(783): Zend_Db_Adapter_Abstract->fetchAll(Object(Varien_Db_Select), Array)
#6 /home/autobadges/public_html/stangcenter.com/lib/Varien/Data/Collection/Db.php(696): Varien_Data_Collection_Db->_fetchAll(Object(Varien_Db_Select))
#7 /home/autobadges/public_html/stangcenter.com/lib/Varien/Data/Collection/Db.php(617): Varien_Data_Collection_Db->getData()
#8 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php(57): Varien_Data_Collection_Db->load()
#9 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Block/Abstract.php(223): Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs->_prepareLayout()
#10 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/Layout.php(430): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
#11 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/Layout.php(446): Mage_Core_Model_Layout->createBlock('adminhtml/catal...', 'product_tabs')
#12 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/Layout.php(238): Mage_Core_Model_Layout->addBlock('adminhtml/catal...', 'product_tabs')
#13 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/Layout.php(204): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#14 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/Layout.php(209): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#15 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Controller/Varien/Action.php(343): Mage_Core_Model_Layout->generateBlocks()
#16 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Controller/Varien/Action.php(270): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#17 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Adminhtml/Controller/Action.php(263): Mage_Core_Controller_Varien_Action->loadLayout(Array, true, true)
#18 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php(246): Mage_Adminhtml_Controller_Action->loadLayout(Array)
#19 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Catalog_ProductController->editAction()
#20 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(253): Mage_Core_Controller_Varien_Action->dispatch('edit')
#21 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#22 /home/autobadges/public_html/stangcenter.com/app/code/core/Mage/Core/Model/App.php(340): Mage_Core_Controller_Varien_Front->dispatch()
#23 /home/autobadges/public_html/stangcenter.com/app/Mage.php(627): Mage_Core_Model_App->run(Array)
#24 /home/autobadges/public_html/stangcenter.com/index.php(80): Mage::run('', 'store')
#25 {main}
write your zend query in a try block
and
catch the exception
Zend_Db_Statement_Mysqli_Exception (check which one you are using 'mysql' or 'mysqli' or 'PDO') in the exception catch code just call {model}->getDefaultAdapter()->closeConnection() and then again call the zend query you have got.
this should solve your problem.
NOTE: Below code is just for reference and should not be used as it is (may have error in it).
try
{
$user = {model}->fetchRow(array('user_id = ?' => $senderid));
}
catch(Zend_Db_Statement_Mysqli_Exception $zenddbmysqliexc)
{
if(stristr($zenddbmysqliexc->getMessage(), 'MySQL server has gone away'))
{
{model}->getDefaultAdapter()->closeConnection();
$user = {model}->fetchRow(array('user_id = ?' => $senderid));
}
}