xpdo
xpdo copied to clipboard
[bug] don't work xPDOManager->createObjectContainer() in MySQL > 8
In src/xPDO/Om/mysql/xPDOManager.php:117 must check is exist table, but this is not working in MySQL8.
When try $manger->createObjectContainer() result is
Error Code: 1146. Table 'eparket.modx_epshop_payment' doesn't exist because table not created yet.`
Fix
$existsStmt = $this->xpdo->query("SELECT table_name FROM information_schema.tables where table_name = $tableName");
if (count($existsStmt->fetchAll()) > 0) {
return true;
}
That is not a fix. You are actually accessing the Database Management system's internal database - not your table.
I use the following function to create the tables:
/**
* Creates the database tables associated with the package.
*
* @return bool
*/
public function createSchemaTables(): bool
{
$out = false;
$schemaObjects = $this->getSchemaObjectNames();
if (count($schemaObjects) > 0) {
$manager = $this->modx->getManager();
if ($manager instanceof xPDOManager) {
$i = 0;
foreach ($schemaObjects as $className) {
$i += ($manager->createObjectContainer($this->packageNamespace . $className) ? 1 : 0);
}
$out = (count($schemaObjects) == $i) ?: false;
}
}
return $out;
}
This might be a bit dated. There were issues with the namespace being correctly translated to table names. See https://github.com/modxcms/xpdo/issues/161