PostgreSQL-For-Wordpress / postgresql-for-wordpress

A maintained fork of https://wordpress.org/plugins/postgresql-for-wordpress/
GNU General Public License v2.0
220 stars 71 forks source link

Switch to mysqli #55

Closed mattbucci closed 10 months ago

mattbucci commented 10 months ago

For compatibility with WP 6.4 we must implement mysqli functions instead of mysql functions in our driver class

See: https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress/issues/54

mattbucci commented 10 months ago

Mysqli driver is now mostly working. I'm able to load the site, browse it and more. But I can't yet make changes to posts or create new posts. Editing via appearance also fails.

The error log contains this.

UPDATE `wp_posts` SET `guid` = '' WHERE `ID` IS NULL
---- converted to ----
UPDATE wp_posts SET guid = '' WHERE `ID` IS NULL
----> ERROR:  syntax error at or near "NULL"

Additionally i'm getting errors about sequences

mattbucci commented 10 months ago

I was able to switch themes fine, but it gave errors


Warning: pg_query(): Query failed: ERROR: currval of sequence "wp_options_seq" is not yet defined in this session in /mnt/shared/sites/monad/wp-content/plugins/pg4wp/driver_pgsql.php on line 1126

Warning: pg_query(): Query failed: ERROR: currval of sequence "wp_options_seq" is not yet defined in this session in /mnt/shared/sites/monad/wp-content/plugins/pg4wp/driver_pgsql.php on line 1126

Warning: pg_query(): Query failed: ERROR: currval of sequence "wp_options_seq" is not yet defined in this session in /mnt/shared/sites/monad/wp-content/plugins/pg4wp/driver_pgsql.php on line 1126
mattbucci commented 10 months ago

Here's another hint:

SELECT CURRVAL('wp_blogmeta_seq')
The latest INSERT query was :
'INSERT INTO wp_blogmeta (blog_id, meta_key, meta_value) VALUES ('1', 'db_version', '56657')'
[1699599422.2772] wpsqli_insert_id() was called with 'wp_blogmeta' and 'blog_id' and returned the error:

it looks like something is wrong with wpsqli_insert_id

mattbucci commented 10 months ago

I think inserts aren't working properly which is what is causing the majority of these issues

mattbucci commented 10 months ago

The issue was the connection was not shared between the insert and the sequence value call.

Changing all functions to pass by reference, updating the global connection more frequently and changing all functions to prefer passed $connection over global fixed the issue.

From what I can see everything is now working correctly but many parts of the driver such as prepared statements aren't implemented. I'm going to merge this, tag a new release and open issues for each function not implemented in the driver.

image