Supporting each other

Community forums

Welcome, Guest
Username: Password: Remember me
The place for more technical questions for those who want to create new pagetypes or bespoke functionality.
  • Page:
  • 1
  • 2

TOPIC:

PHP - unable to update database 7 years 1 month ago #4699

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
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.

Please Log in or Create an account to join the conversation.

PHP - unable to update database 7 years 1 month ago #4700

  • tom
  • tom's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 1283
  • Thank you received: 324
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.

Please Log in or Create an account to join the conversation.

PHP - unable to update database 7 years 1 month ago #4701

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
Some snippets of the code. From upgrade.php I have used:
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:
$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.

Please Log in or Create an account to join the conversation.

PHP - unable to update database 7 years 1 month ago #4702

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
The upgrade file in the github repo can be found
Part of the message is hidden for the guests. Please log in or register to see it.

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.

Please Log in or Create an account to join the conversation.

PHP - unable to update database 7 years 1 month ago #4703

  • ronm
  • ronm's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 850
  • Thank you received: 261
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/

Please Log in or Create an account to join the conversation.

PHP - unable to update database 7 years 1 month ago #4704

  • jayaich
  • jayaich's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 82
  • Thank you received: 5
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 :-(

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: JohnSmith
Time to create page: 0.048 seconds
Copyright © 2024 The Xerte Project.
Xerte logo Apereo logo OSI Logo

Search