Poll Object not Working on Home Page
Author: Dave G.
Visited 1497,
Followers 1,
Shared 0
Usting X5 v15 with LAMP website running 5.5 - user selects Poll Object and receives "Temporary Error, please try later.", where it looks like the function might be failing in the AJAX script as Database connectivity and php caching is "Passed" in the X5 control panel (site/admin).
The Apache Server is configured to process .cgi .pl .plx .ppl .perl - is something further required to be configured on the Apache Server or within the PHP module for this function to work correctly on the server (note: tests successfully on Windows 10 Desktop)?
Website URL: dev.atfonline.com.au
Posted on the
Author
I have tracked this problem down further and although all tests of database connectivity are good, the object appears to have a issue with creating the table for the poll results even though all configuratios look correct - what could I be missing on the server vs desktop?
// Sever error log
[07-May-2018 07:44:01 UTC] Error creating table: CREATE command denied to user 'atfonlin_webadm'@'localhost' for table 'General_Poll_1'
[07-May-2018 08:05:01 UTC] Error creating table: CREATE command denied to user 'atfonlin_webadm'@'localhost' for table 'General_Poll_2'
// from x5settings.php
$imSettings['databases'] = array(
'ygfq1lrm' => array(
'description' => 'atfonlin_temp',
'host' => 'localhost',
'database' => 'MySQL',
'user' => 'atfonlin_webadm',
'password' => 'ATF$council#2018'
),
'cibb1cgt' => array(
'description' => 'atfonlin_forum',
'host' => 'localhost',
'database' => 'MySQL',
'user' => 'atfonlin_webadm',
'password' => 'ATF$council#2018'
)
);
// see attached file of server database confiuration where user has full priviliages
Author
After much investigation now reporting this as a official bug; Found the problem, the X5 software assumes and sets up a connection to the default (first) MySQL database and does not use its configuration information nor newer connection PHP connection methods (PDO vs. MySQL_Connect) to specify the database connection. Thus, as it happens and configured, the specified user does not have privilege on the connected (first vs. second database) and therefore the table creation fails for the object.
// x5engine.php does not utilize the Description form its configuration, thus assumes it is always the default database
// A better method would be to use PDO vs. MySQLConnect to open the specified database for x5 in description or
//$this->conn = @PDO(‘mysql:dbname=ygfq1lrm.description;%host’, $user, $pwd). See code below from x5engine.php
// where the description field is not passed nor is it used in setting up the connection to the database.
/**
* @summary
* A database driver class which access to the DB using the "mysql_" functions
*
* To use this class, you must include __x5engine.php__ in your code.
*
* @description Create a new ImDb Object
*
* @ignore
* @class
* @constructor
*
* @param {string} $host The database host address
* @param {string} $user The database username
* @param {string} $pwd The database password
* @param {string} $db The database name (or MySQL)
*/
class MySQLDriver implements DatabaseAccess
{
var $conn;
var $db;
var $db_name;
var $engine = "MYISAM";
function __construct($host, $user, $pwd, $db)
{
$this->setUp($host, $user, $pwd, $db);
}
function ImDb($host, $user, $pwd, $db)
{
$this->setUp($host, $user, $pwd, $db);
}
function setUp($host, $user, $pwd, $db)
{
$this->db_name = $db;
$this->conn = @mysql_connect($host, $user, $pwd);
if ($this->conn === false)
return;
$this->db = @mysql_select_db($db, $this->conn);
if ($this->db === false)
return;
if (function_exists('mysql_set_charset'))
@mysql_set_charset("utf8", $this->conn);
else
@mysql_query('SET NAMES "utf8"', $this->conn);
}
Hi Dave.
I turned this topic into an Idea, as I believe it better suits the general outcome of this topic.
We haven't received any reports about this failing on an online server, meaning that there could be something different on your current installation that works in a way that is different to an online hosting.
I'll leave this topic untouched in order to forward this information correctly, so that it may get consulted later on.
Thank you for taking the time to investigate this
Stefano
Author
Thanks Stefano, on my desktop I am running only the single database instance of MySQL, where on the server there are multiple instances. While there could possibly be a configuration issue on the server, unless localhost is appended with a port for the specific database the connection I believe will always be to the first instance and thus fail if the user is not registered.
Thus I still see this as a bug in that the specified database name is not being used for the connection, which is supported by the newer PDO function. As ImDB is called from multiple locations to create / test the database connection, at the moment it is easier to hack the php but suspose we can argue as to if this is an idea vs. bug.
My reasoning is that in the majority of instances the default MySQL would be used by the X5 website or be in a separate location for testing, in this instance the default database is being used for the current website software and we have created a second database instance (which is specified in Step 1 but not used for the connection). Thus the connection is not being setup correctly.
Author
Stefano, I resolved the (embarrissing) online configuration issue and now working fine. Althought, I still recommend this being continued as an idea to change to PDO for opening the database connection (my syntax is incorrect in my earlier post) but did get this fixed as a hack into the x5engine.php file.
Kind Regards!
Dave