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

PHP - unable to update database

Plus d'informations
il y a 8 ans 10 mois #4699 par jayaich
PHP - unable to update database a été créé par 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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #4700 par tom
Réponse de tom sur le sujet 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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #4701 par jayaich
Réponse de jayaich sur le sujet 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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #4702 par jayaich
Réponse de jayaich sur le sujet PHP - unable to update database
The upgrade file in the github repo can be found
Quelque chose est masqué pour les invités. Veuillez vous connecter ou vous enregistrer pour le visualiser.

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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #4703 par ronm
Réponse de ronm sur le sujet 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/

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 10 mois #4704 par jayaich
Réponse de jayaich sur le sujet 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 :-(

Connexion ou Créer un compte pour participer à la conversation.

Modérateurs: JohnSmith
Temps de génération de la page : 0.151 secondes
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo