Anyone know what is going on with this SQL error when trying to install a module?

I am playing around with module development and getting getting an SQL error.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘mytestmodule’‘,’‘1.0.0’‘, 1)’ at line 1

Here is a basic module.xml I have

<?xml version="1.0" encoding="UTF-8"?>
<module>
	<rawname>mytestmodule</rawname>
	<repo>extended</repo>
	<name>My Test Module</name>
	<version>1.0.0</version>
	<publisher>Community</publisher>
	<license>GPLv2+</license>
	<category>Applications</category>
	<description>Just Testing</description>
	<depends>
		<version>17.0</version>
	</depends>
	<install>
		<script>install.php</script>
	</install>
	<uninstall>
		<script>uninstall.php</script>
	</uninstall>
	<menuitems>
		<mytestmodule>My Test Module</mytestmodule>
	</menuitems>
	<supported>
		<version>17.0</version>
	</supported>
</module>

In case it was me doing something wrong, for testing, I can take an .xml file from another module put it in there and I would get a similar result, but with the name of that module, and the version of what is in that module.

Doing more testing, if I modify one of the official modules by adding some of my own code, the install goes fine, but then I get the warning about module not having a valid certificate.

So I tracked down this $sql = "INSERT INTO modules (modulename, version, enabled) … line in

/var/www/html/admin/libraries/modulefunctions.class.php

Before that line I put

error_log("DEBUG_RAWNAME=[" . $modules[$modulename]['rawname'] . "]");
error_log("DEBUG_VERSION=[" . $modules[$modulename]['version'] . "]");

Then ran the following commands

fwconsole ma install mytestmodule
My Test Module module installation started Database tables created successfully My Test Module module installation completed
DEBUG_RAWNAME=[mytestmodule]
DEBUG_VERSION=[1.0.0]

In Database.class.php line 278: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘mytestmodule’‘,’‘1.0.0’‘, 1)’ at line 1

Where did you get this module.xml structure from? It looks incorrect.

That should just be <supported>17.0</supported>

I don’t think these are valid options, I see no real reference to them in documentation. It would most like be the following but you should use the install() and uninstall() function within Module.class.php for the BMO.

<fileinclude>
  <install>install.php</install>
  <uninstall>uninstall.php</uninstall>
</fileinclude>
1 Like

I don’t recall where I found it as it’s been a while as I just am working on it on and off. I am back on, but past couple of days there was a massive freak electrical storm which damaged a lot of equipment, and was busy dealing with that.

Anyway, the area you pointed out as not being valid may be true, but does not address the issue. As I previously mentioned, just changing a few line of code in an actual module and installing the changed module reports only no valid certificate for it.

However, taking any module.xml file from another module and replacing it with mine, and I get the same type of error.

OK can you uninstall another module and reinstall it? Do you get that error? What version of framework and core are you on? Can you share this module structure?

I found the problem by running “php -l myfile.php” on any and all the .php files I had in it. i accidentally had an / in there on one line

PHP Parse error: syntax error, unexpected token "/", expecting end of file

The module installed fine now.

Thanks for taking the time to look this over and respond.

I don’t know if you are aware, but you can download this tool to beguin a module from scratch. : freepbxgenerator.phar
This tool is pretty old but works good to create a module quickly.

1 Like

Thanks for that info. I did not know about that.

1 Like