Good day, eveyrone!
I'm trying to fetch data from Oracle database via Phalcon\Mvc\Model\Query\Builder, but resultset allways empty.
// APPLICATION_ROOT/app/models/Package.php
<?php
use Phalcon\MVC\Model;
class Package extends Model
{
public function getSource()
{
return 'RADIO_PACKAGE';
}
}
The controller class:
public function indexAction()
{
$packages = Package::find();
var_dump($packages->toArray()); // null
$query = $this->modelsManager->createBuilder()->from('Package')->getQuery();
var_dump($query->execute()->toArray()); // null
// But the direct access to database returns rows
$PDO = $this->getDI()->get('db')->getInternalHandler();
var_dump($PDO->query('SELECT * FROM RADIO_PACKAGE')->fetchAll()); // returns 23 rows
}
Does anyone know what the problem is?
I tried Phalcon 1.1.0 and 1.2.0.
PDO_OCI driver has been installed from PHP 5.4.16 source.
PHP version is 5.4.11.
Oracle version is "Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit"
Fixed in 1.2.0 branch, discussion about the problem: http://forum.phalconphp.com/discussion/464/empty-resultset-when-using-phalcon-mvc-model-query-builder
Do you have in public/index.php a setup for Loader ?
Something like
$loader = new \Phalcon\Loader();
$loader->registerDirs(
array(
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->pluginsDir
)
)->register();
Related
I have app in Kohana 3.1 and it was woring fine on PHP 5.4
But after migration this DB query is not working:
DB::select(array('MAX("art_nr")', 'art_nr'))->from('wi_artykuly')->execute()->get('art_nr');
If any function is depricated or something?
EDIT
Here's full function:
public function create(Validation $validation = NULL)
{
if(! isset($this->art_nr))
{
$intMax = DB::select(array('MAX("art_nr")', 'art_nr'))->from('wi_artykuly')->execute()->get('art_nr');
$this->art_nr = $intMax+1;
}
return parent::create($validation);
}
I've changed DB:query to PDO prepare and fetch.
If anyone wants a code please write.
I am new to yii2 and I have created a form, however it is showing the following error while loading the page:
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: yii\web\Request::post()
The code in studController
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
if(($model->load(Yii::$app->request->post())) && $model->validate())
{
echo "validate";
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
ok
i also faced that problem and i had sorted out also
in yii2 you have to check that if form is posted or not ?
if form posted then you have to fetch data or print data
try my code it working in my case with same error
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
$request = Yii::$app->request;
if($request->isPost)
{
if(($model->load($request->post)) && $model->validate())
{
print_r($request->post['Stud']);
}
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
Check namespace use Yii in your controller
OR
I think this is again the composer dependency resolver doing unexpected things:
you require yiisoft/yii2 in your composer.json but do not have the composer asset plugin installed.
then the dependency resolver does not find packages with vendor bower-asset so it looks for other versions of yiisoft/yii2 that do not have conflict
The result is to install the beta version of yii2 to be installed
The correct solution as already mentioned is to install the composer-asset-plugin:
php composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
I am trying to test around Agile Toolkit with oracle, after seting up a model and trying to show a grid it says "No records found"...
Let me tell you what I did, since i've been guessing most of all configuration as I found no guides for oracle.
My Oracle connection string in agiletoolkit config-default.php file looks like this:
$config['dsn']= array( 'oci:dbname=localhost/MYDATABASE', 'MYUSER', 'MYPASSWORD' );
To fix the driver not found error, I enabled extension=php_pdo_oci8.dll in the php.ini file from my apache installation.
Then there was an error about a missing "oci.php", to solve that I had to create my own file like this:
class DB_dsql_oci extends DB_dsql {
function limit($cnt,$shift=0){
$cnt+=$shift;
$this->where('NUM_ROWS>=',$shift);
$this->where('NUM_ROWS<',$cnt);
return $this;
}
function render_limit(){
return '';
}
}
and placed it at: ...atk4\lib\DB\dsql
To fix the special chars error from oracle , I set line 59 on /atk4/lib/DB/dsql.php to empty string like this: public $bt='';
I manage to run the database test, and it says "Successfully connected to database."
Then I created a model "lib\Model\Mytable.php" like this:
<?php
class Model_Mytable extends Model_Table {
public $table = "MYTABLE";
function init(){
parent::init();
$this->addField('ID');
$this->addField('NAME');
$this->addField('INIDATE');
$this->addField('ENDDATE');
}
?>
After that, I made a new page and tried to use the model like this:
<?php
class page_test extends Page {
function init(){
parent::init();
$form = $this->add('Grid');
$form->setModel('Mytable');
}
}
?>
After refreshing the browser, it will show the grid saying " No Records found"
I wonder whats happening, that table has records no doubt, all data is committed, and im sure oracle is parsing queries because if I miss a column name an oracle error will raise.
Any clue?
This is how you can simply set DSQL as your View (Grid for example) data source:
class page_test extends Page_Basic
{
function init()
{
parent::init();
// DSQL
$q = $this->api->db->dsql();
$q->table('MYTABLE')
->field('DNAME')
->field('INIDATE');
// Create grid and set DSQL as its data source
$g = $this->add('Grid');
$g->addColumn('DNAME');
$g->addColumn('INIDATE');
$g->setSource($q);
// better add paginator too or your grid can become huge :)
$g->addPaginator();
}
}
i just installed a new component in my site but when i click on component settings button in the backend i am getting this message:
Fatal error: Call to a member function loadByOption() on a non-object in /mysite.com/administrator/components/com_sigpro/models/settings.php on line 32
the file contains this code:
defined('_JEXEC') or die ;
class SigProModelSettings extends SigProModel
{
protected $extensionID = null;
public function getForm()
{
$option = $this->getState('option');
if (version_compare(JVERSION, '2.5.0', 'ge'))
{
$component = JComponentHelper::getComponent($option);
$this->extensionID = $component->id;
JForm::addFormPath(JPATH_ADMINISTRATOR.'/components/'.$option);
$form = JForm::getInstance($option.'.settings', 'config', array('control' => 'jform'), false, '/config');
$form->bind($component->params);
}
else
{
$component = JTable::getInstance('component');
$component->loadByOption($option);
$this->extensionID = $component->id;
$form = new JParameter($component->params, JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'config.xml');
}
return $form;
}
PS my site is running Joomla 1.7.5 stable version and i cant upgrade it to 2.5 because the site is online and productive some components dont works on version 2.5 .
So i will appreciate it if someone can help me fix this error.
Thanks in advance
you 1.6 needs 1.6 specific modules, components & plugins. You'll need to find a 1.6 compatible version or alternative or check the permissions on /configuration.php
Looks like the table class is not present in your file system. It should have been there in the /mysite.com/administrator/components/com_sigpro/tables folder , somewhere ( may vary depending on the code, but looks like they have not included a custom path ). The class should extends JTable class.
I need some help to understand CodeIgniter's hook logic to adapt the code to my needs.
The page : https://www.codeigniter.com/user_guide/general/hooks.html
In fact, I had to modify the database driver for MySQL from this :
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return '('.implode(', ', $tables).')';
}
to this :
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return implode(', ', $tables);
}
I made this mod to use UNION queries using Active Record library.
Can someone help me to make a hook in order to prevent my modification from being overwritten when I update the core system ?
Thanks in advance !
You can find the instructions for extending the db drivers on the CodeIgniter Wiki - Extending Database Drivers
The solution comes in 3 simple steps:
1) Extend your loader class by creating the file MY_Loader.php. Put it
into your libraries directory in the application path (or if you are
using CI 2.x.x then put it into application\core\ path):
2) Add the following function to your MY_Loader class:
3) Create your Database driver extension class, that you name
MY_DB_mysql_driver.php (or substitute the mysql part for whatever
driver you use - do that also for the classnames in the code below!).
Put this file also in your applications libraries directory:
Your custom DB driver will look like this
class MY_DB_mysql_driver extends CI_DB_mysql_driver {
function __construct($params){
parent::__construct($params);
log_message('debug', 'Extended DB driver class instantiated!');
}
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return implode(', ', $tables);
}
}