I wonder how can I find my moodle's database contents.
I want to elaborate users etc.
My first try is with PHP code using global $DB but there is an error message:
Fatal error: Call to a member function get_record() on a non-object in C:\xampp\htdocs\test.php on line 3
I use the getrecord() function but I didn't do it right.
Can anybody help me? The name of my database is "base".
Note: moodle version is 2.7.2
This is an example that should allow you to access the Moodle DB.
require_once(dirname(__FILE__).'/../../config.php'; // Insert as many '/../' as you need to get from the subdirectory your file is in, back up to Moodle's config.php
function my_function() {
global $DB;
$record = $DB->get_record('user', array('id' => 2));
var_dump($record);
}
my_function();
Related
I am trying to call a function from one file to another in PHP, however, I am getting the following error:
Fatal error: Call to undefined method SQLite3::print_model_query_form()
I have two files. The first - dbfunctions.php contains the method print_model_query_form().
The second file query_models contains the following code:
include_once("functions/dbfunctions.php");
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
print $db->print_model_query_form("query_models.php");
The function looks a little like this:
function print_model_query_form($action, $current_values = 0){
$db = new SQLite3('D:\xampp\sim\htdocs\dis_sqlite_database\disSQL3.db');
if($current_values){
// set to previous values.
}else{
// get POST values.
}
// Code to print query form.
}
Thanks in advance for any help.
Since you only hit fatal error on 3rd line, $db should be instantiated successfully. So, the issue should be the print_model_query_form method.
Referring to PHP:SQLite3 - Manual
, there is no such built in method called print_model_query_form.
[Edit 1]
Try to use require_once instead of include_once to make sure you have included dbfunctions.php successfully.
[Edit 2]
Check If you are using PHP's built in SQLite3 class (check your php.ini for extension=php_sqlite3.dll or extension=php_sqlite3.so).
If this is the case, check your dbfunctions.php for:-
class Something
new SQLite3
function print_model_query_form
If all the above exists then you should replace your 2nd line with,
$db = new Something(..);
Note: It would be better if you can show dbfunctions.php instead or letting us make assumptions based on guessing.
I have Joomla! 1.7.2 Stable and when I try to Log in to administration area I get this error
Fatal error: Call to a member function load() on a non-object in /home/shomos1/public_html/portal/libraries/joomla/user/user.php on line 822
this is the error line in my user.php
public function load($id)
{
// Create the user table object
$table = $this->getTable();
var_dump($table);
// Load the JUserModel object based on the user id or throw a warning.
if (!$table->load($id)) {
JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('JLIB_USER_ERROR_UNABLE_TO_LOAD_USER', $id));
return false;
}
// Set the user parameters using the default XML file. We might want to
// extend this in the future to allow for the ability to have custom
// user parameters, but for right now we'll leave it how it is.
$this->_params->loadString($table->params);
// Assuming all is well at this point lets bind the data
$this->setProperties($table->getProperties());
return true;
}
}
I am not good in Joomla and I can't understand what is the problem there
please need help what can I do to solve this problem
Thanks
the default com_user component is conflicting with your component so you must rename your component files they must not have name "user" ...
Now I am learning Codeigniter. I have more databases, so I choosed this time Anketa one.
Why is error :
**Fatal error: Call to a member function query() on a non-object in /var/www/domains/svastara/application/controllers/anketa.php on line 12** ???
I chacked, the user and pass in database is ok, database is loaded in conf, and chacked the table name. So what more?
$this->db = $this->load->database('anketa');
$q = $this->db->query("SELECT * FROM anketaip");
if($q->num_rows()>0){
foreach ($q->result() as $row)
{
$data[] = $row;
}
}return $data;
$this->load->view('anketa_nova', $data);
Below line doesn't return you database object until you pass second argument as TRUE
Change:
$this->db = $this->load->database('anketa');
To
$newdb = $this->load->database('anketa',TRUE);
$q = $newdb->query("SELECT * FROM anketaip");
Reference Link: http://codeigniter.com/user_guide/database/connecting.html
You dont have to do this
$this->db = $this->load->database('anketa');
You can simply do it like this
$this->load->database('anketa');
$this->db->query('blah blah');
Also make sure database exists and you have rights to access it.
Posibly you need to load the DB library, please check in you autoload.php that you are loading the database library
$autoload['libraries'] = array('database');
Or load the library in your controller
$this->load->library('database');
Hi Daniela,
I think this resource link may help u. Because when you are using more than one database at a time u need to follow the syntax explained by GDB in his post. But you said unable to access to database that means it's not able to detect database,php in config folder. So put that file link externally in your php file. Then it may work.
http://codeigniter.com/forums/viewthread/191673/
That was the problem.
I set $db['default']['autoinit'] = TRUE
and it worked.
Hi i have uploaded a template on a website i have created using joomla and when i apply the template and visit my website i get the following error,
Fatal Error : call to a member function Fatal Error : call to a member function getCfg () on a non-object in /home/a7751589/public_html/templates/themza_j15_11/index.php on line 21.
the code on the index.php line 21 is as below.
$sliderVars['directionNav']=($this->params->get('sliderVars_directionNav')==='true' or $this->params->get('sliderVars_directionNav')==='false')?$this->params->get('sliderVars_directionNav'):'true';
please advise what i need to do to make this work,
Thank you
i recommend to checking compatibility of your theme with components...
check its http://forum.joomla.org/viewtopic.php?t=637126
Agree with GkDreamz - the "...J15..." part in your template name makes me think it's a 1.5 template that you're probably installing on a new 2.5 version.
When this happened to me, I noticed this in the PHP script:
global $mainframe;
Bear in mind that starting with Joomla 2.5, $mainframe is no longer using global, so it should be this:
$mainframe = & JFactory::getApplication();
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
I get the error "Cannot redeclare function getContactActiveEmails"
The line number it gives is the last line of the function - the }
All files are being called with require_once. This is the only place in the entire codebase where getContactActiveEmails is being defined. Why is this?
It is very clear from the error your function is defined twice hence you are getting the error.
I would recommend that check if the function is already defined before declaring it.
if (!function_exists('getContactActiveEmails'))
{
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
}
solution by #Shakti Singh will work, but keep in mind that you are loosing control of your code - you do not know where is this function declared and what does it return, so I suggest looking for it
Try case insensitive search, many text editors and IDEs search case-sensitive by default and your function can be as well declared as getcontactactiveemails somewhere.
If still no luck make php say something about this function, using Reflection extension
Example usage of reflection:
if(function_exists('getContactActiveEmails')){
$myfunc = new ReflectionFunction('getContactActiveEmails');
echo 'Function is declared in '.$myfunc->getFileName().
' starting from line '.$myfunc->getStartLine().
' to '.$myfunc->getEndLine();
die;
}
More about Reflection
I'm getting the same issue. I have a standard file called adhoc.inc.php which is imported into almost every php file on my site. With no changes being made to any code over night i started seeing the error
[13-Jul-2013 21:19:22 Australia/Sydney] PHP Fatal error: Cannot redeclare checkloggedin() in /Applications/MAMP/htdocs/mycobber/util/adhoc.inc.php on line 4
Initially I only got it in a few files so i just commented out this import and it worked. Suddenly, again no changes, I was getting this in every file i loaded. I figured this wasn't me so I restarted my MAMP servers (apache and mysql) and then it went away.
Has anyone seen this before?
This error occurs if you have your function defined in a loop, since you're trying to define it in each iteration.