When i enter this code
<?php
db_set_active('stats'); // Use my_other_db
// Read all fields from the club table.
$select = db_select('cricket__50over__batting__top_run_scored', 'c');
$select->fields('c', array('Name','Runs'))//SELECT the fields from c
->orderBy('Runs', 'DESC');//ORDER BY Runs
//returns each selected record as an object instead of an array.
$entries = $select->execute()->fetchAll();
$rows = array();
foreach ($entries as $entry) {
// Sanitize the data before handing it off to the theme layer.
$rows[] = array_map('check_plain', (array) $entry);
}
// Make a table for them.
$header = array( t('Name'), t('Runs'));
$output = theme('table', array('header' => $header, 'rows' => $rows));
echo $output;
db_set_active(); // Go back to Drupal's db.
?>
in the body of a panel pane the desired result of the code shows perfectly fine in the preview but when i save the panel and move to the page where the panel is pathed the page doesn't load but instead gives me this error
/* edit this piece of code in the body of a content type*/
Additional uncaught exception thrown while handling exception.
Original
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'stats.panels_layout' doesn't exist: SELECT t__0.* FROM {panels_layout} t__0 WHERE (plugin = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => flexible ) in ctools_export_load_object() (line 427 of /opt/lampp/htdocs/xxxxxx/sites/all/modules/ctools/includes/export.inc).
Additional
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'stats.stylizer' doesn't exist: SELECT t__0.* FROM {stylizer} t__0; Array ( ) in ctools_export_load_object() (line 427 of /opt/lampp/htdocs/xxxxx/sites/all/modules/ctools/includes/export.inc).
Uncaught exception thrown in session handler.
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'stats.sessions' doesn't exist: SELECT 1 AS expression FROM {sessions} sessions WHERE ( (sid = :db_condition_placeholder_0) AND (ssid = :db_condition_placeholder_1) ) FOR UPDATE; Array ( [:db_condition_placeholder_0] => dbm6wjQN1g9F0uoE0-qtWVc5_g-fRdKUR9iB52OwYqQ [:db_condition_placeholder_1] => ) in _drupal_session_write() (line 206 of /opt/lampp/htdocs/xxxxx/includes/session.inc).
Thanks in advance for any advance and tips for solving this error.
Comments
Comment #1
marcingy commentedLooks like wrong project
Comment #2
bajah commentedok, so any idea as to what may have caused this error.
Comment #3
merlinofchaos commentedI would consider moving the db_set_active() to as soon after you run your query as you can.
I don't really see why this got moved into the Panels queue, though -- if anything this looks like a problem with db_set_active() or something, or the code here.
I don't really have a lot of good advice for you, other than to do some debugging to see if you can understand why 'stats' is the active db when those calls are made.
One debugging tool you could use would be to dump a debug_backtrace() in an exception handler and see if you can determine what state the system is in when those exceptions are called. It's weird, though, because you're not really doing much.
I don't really see how Panels has much to do with this beyond the weirdness that you're running it within Panels, but Panels doesn't do *anything* with db_set_active.
Comment #4
bajah commented@merlinofchaos, thanks for the response and u are right it has nothing to do with panels after i did some debugging i found out that the problem might be with the theme that im using which is zeropoint. I entered the same code in a new content type that i created and now the error changed to:
Fatal error: Unsupported operand types in /opt/lampp/htdocs/sysctest/includes/theme.inc on line 621
Uncaught exception thrown in session handler.
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'stats.sessions' doesn't exist: SELECT 1 AS expression FROM {sessions} sessions WHERE ( (sid = :db_condition_placeholder_0) AND (ssid = :db_condition_placeholder_1) ) FOR UPDATE; Array ( [:db_condition_placeholder_0] => dbm6wjQN1g9F0uoE0-qtWVc5_g-fRdKUR9iB52OwYqQ [:db_condition_placeholder_1] => ) in _drupal_session_write() (line 206 of /opt/lampp/htdocs/sysctest/includes/session.inc).
Its access stats database because i what to show some information from that database and not from the default drupal database, from what i can see is that the code is fine because if i preview before i save i am able to see the desired result but when i save it and reload the page thats when i get the error.
Comment #5
bajah commentedthe problem isn't the theme either, cause i tried a different theme but still having the same problem. what i don't understand is y is it looking for the table stats.sessions.
Comment #6
merlinofchaos commentedWell, logically what is happening is that some other database calls are happening when the database is set to 'stats'. There are only two real possibilities:
1) These calls are happening prior to you resetting db_set_active() to the standard database
2) Your db_set_active() call is failing.
This can be verified by putting some debug messages in to see the timing of the errors.
Comment #7
bajah commented@merlinofchaos just wanna say thanks alot for the tip about moving db_set_active right after the query. That did the trick.
Comment #8
merlinofchaos commentedComment #9.0
(not verified) commentedremoved unnecessary comments