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

PHP - unable to update database

  • jayaich
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 10 months ago #4705 by jayaich
Replied by jayaich on topic PHP - unable to update database
Okay, on my modified upgrade program I had to add:
Code:
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
after establishing the connection.
Running the program I then get the following output shown:

Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1142 ALTER command denied to user 'xerteuser'@'localhost' for table 'sitedetails' in /var/www/html/xerte-3.5/jhf.php on line 37
Array ( [0] => 00000 [1] => [2] => )

Line 37 corresponds to the execute statement.

It's odd though because the user does have permissions, and if I run the command by hand as that user, then it works.
So, not sure if I'm a bit closer with this or not!

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

More
8 years 10 months ago - 8 years 10 months ago #4706 by tom
Replied by tom on topic PHP - unable to update database
Found it.

Because I coincidently happened to run into the same problem....

The _db_add_field() function basically is not able to handle fields of type 'text'.

A type text is a blob in mysql, and blob types cannot have a default value, but _db_add_field() tries to set the default value.

So either change the type to a varchar, or modify _db_add_field() to be able to handle text fields.

I haven't touched the code.
Last edit: 8 years 10 months ago by tom.

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

  • jayaich
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 10 months ago #4708 by jayaich
Replied by jayaich on topic PHP - unable to update database
Erm... no :-)
I know what you mean about globs not having a default (despite NULL seeming to be an obvious default for text fields). But mysql does not actually object to a TEXT default so long as it is '' (2 single quotes) or set to NULL (not the string "NULL" which _db_add_field does.) Setting any other default does give an error saying that globs/text cannot have a default.
(Tested with mariadb 5.5.56).
I did try setting the field to something other than text (I used char(255)), but it gave the same error.

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

  • jayaich
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
8 years 10 months ago #4709 by jayaich
Replied by jayaich on topic PHP - unable to update database
Okay, the problem was permissions!
The error is confusing because it says

...ALTER command denied to user 'xerteuser'@'localhost' for table...

If I check that users permissions then they have all permissions.
However, in database.php the host is '127.0.0.1', and for that user ('xerteuser'@'127.0.0.1') the permissions are just select, insert etc. So by allowing the user 'xerteuser' @'127.0.0.1' the ALTER permission, the script then works fine in adding the new field.
I guess when I added the field manually from the command line it was because I was seen as being from 'localhost'.

Anyway, problem solved. Many thanks for your help.

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

Moderators: JohnSmith
Time to create page: 0.138 seconds
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo