The place for more technical questions for those who want to create new pagetypes or bespoke functionality.

PHP - unable to update database

  • jayaich
  • Onderwerp Auteur
  • Offline
  • Premium lid
  • Premium lid
Meer
8 jaren 10 maanden geleden #4699 door jayaich
PHP - unable to update database werd gestart door jayaich
Hello,

I have modified 'upgrade.php' to add a new field to the 'sitedetails' database table. I have used the '_db_field_exists' function to make sure the field doesn't already exists, and that works fine. I then call '_db_add_field' to add the field.
In order to test that just this bit works I stripped out all the numerical upgrade functions ('upgrade_1', 'upgrade_2' etc) except the one I want to run. However, the call to '_db_add_field' always seems to fail.
I have modified the PHP file further to check that the DB connection is okay (it is), and that the prepare statement is okay (it is). It is the 'execute' statement which fails. What is worse is that it fails with an error code of 00000!

I am somewhat stumped with this. It is part of a pull request waiting to be pushed to github, but I am slightly loathe to do that without having tested it. I have googled about this, but can find nothing to explain what might be wrong.
I have tried running a full upgrade but that fails with creating the config table (again error 0). I have disabled the local iptables firewall and SELinux (it's running on a Linux server), but neither made any difference. I have checked the server logs, the Apache and mariadb logs and found nothing useful.
If I run the mysql statement ('alter table... add column...') by hand using the Xerte database userid, then it works fine.

Anyone any ideas about this?

Thanks.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
8 jaren 10 maanden geleden #4700 door tom
Beantwoord door tom in topic PHP - unable to update database
No, but you can send the upgrade.php script to me by PM, or pint me to your github repo, and I'll have a look.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • jayaich
  • Onderwerp Auteur
  • Offline
  • Premium lid
  • Premium lid
Meer
8 jaren 10 maanden geleden #4701 door jayaich
Beantwoord door jayaich in topic PHP - unable to update database
Some snippets of the code. From upgrade.php I have used:
Code:
if (! _db_field_exists('sitedetails', 'file_extensions')) { $error1 = _db_add_field('sitedetails', 'file_extensions', 'TEXT', '', 'LRS_Secret');

The function '_db_add_field' w\s modified to include:
Code:
$connection = database_connect(); if ($connection === false) { echo "<p>Connection failed</p>"; return false; } $statement = $connection->prepare($query); if ($statement === false) { echo "<p>Prepare failed</p>"; return false; } $params = array(); $ok = $statement->execute($params); if ($ok === true) { return $ok; } else { echo "<p>Execute failed: Code: " . $connection->errorCode() . " Info: " . print_r($connection->errorInfo()) . "</p>"; return false; }

When I run the code it always fails with the 'Execute failed...' error.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • jayaich
  • Onderwerp Auteur
  • Offline
  • Premium lid
  • Premium lid
Meer
8 jaren 10 maanden geleden #4702 door jayaich
Beantwoord door jayaich in topic PHP - unable to update database
The upgrade file in the github repo can be found
Een deel is verborgen voor gasten. Log-in of registreer om het te kunnen bekijken.

This is a different field from the one I was working on today, but it exhibits exactly the same problem. I have added the 'upgrade_10' and 'upgrade_11' functions. Upgrade_10 just modifies an existing field, and that works. Upgrade_11 adds a new field, and that fails.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
8 jaren 10 maanden geleden #4703 door ronm
Beantwoord door ronm in topic PHP - unable to update database
Sorry quickly skim reading this but just wondering... dbuser permissions? e.g. updating existing fields different to adding new fields.

Just a quick thought.

Xerte developer & trainer
e-learning & m-learning consultant
mitchellmedia.co.uk | xerteacademy.com | learningapps.co.uk
Note: Support here is voluntary and meant for users to support each other.
Need direct commercial support with Xerte? mitchellmedia.co.uk/contact/

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

  • jayaich
  • Onderwerp Auteur
  • Offline
  • Premium lid
  • Premium lid
Meer
8 jaren 10 maanden geleden #4704 door jayaich
Beantwoord door jayaich in topic PHP - unable to update database
Good idea, but this is on a test server, so at the moment the Xerte database user has all access to the database.

I very much feel it is going to be something simple/stupid, but I just can't think or see what :-(

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Moderators: JohnSmith
Tijd voor maken pagina: 0.170 seconden
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo