Ajax-PHP Rating Stars Script with SQLite

Place for comments, problems, questions, or any issue related to the JavaScript / PHP scripts from this site.
User avatar
Alecos
Posts: 18

Ajax-PHP Rating Stars Script with SQLite

I use always the script: //coursesweb.net/php-mysql/rating-stars-script-ajax-php_s2 from this great site!
In the last week I migrated all my scripts to SQLite PDO with prepare statements and using PHP 7.1.
I would know how modify your script Ajax-PHP Rating Stars Script for using it with SQLIte with PDO using prepare... MySQL is really expensive vs SQLite which is free and very comfortable.
Maybe a new script that uses SQLite PDO can be done?

Thanks in advance for every reply to my help request.

Kind Regard.
--
Alessandro

Admin Posts: 805
Hello,
I not know to work with SQLite, not know its syntax.
But you can use the "txt" option to save rating script data in text files (in the "ratingtxt/" folder); it will use the php only.
In ratings.php file just set:

Code: Select all

define('SVRATING', 'txt');

Alecos Posts: 18
Thanks! At the moment I still using txt data file... txt data file do not cover race condition even if it's mitigated by IP rating in the 24 hours.

Admin Posts: 805
I updated the Ajax-PHP Rating Stars Script to work with SQLite too.
- Download again the script, see the readme file and test it.

Alecos Posts: 18
I forget to say thanks for your great effort! Thank you!

Alecos Posts: 18
I tested Your Script with SQlite and works great!!! No Race Condition and a portable database that I can backup downloading it from my server using FTP client.

I protect my db from being downloaded using htaccess:

Code: Select all

################################################################################
############################# Protect SQlite DataBase ##########################
################################################################################
<FilesMatch "\.(sqlite|db)$">
  Order Allow,Deny
  Deny from all
</FilesMatch>
I named my database rating.sqlite so can be protected by .htaccess

Alecos Posts: 18
I noted a strange thing that don't happen with previous version of your script... your script released today (September 05 2017) sucks a lot of resources and sometime blocks my website when the script is loading... sounds like performance issue... maybe solved by calling every 1000 instead 400? Maybe the whole script need to be optimized?

Admin Posts: 805
It is not called every 400 miolliseconds, but only once, after 400 milliseconds when the page is loaded.

Code: Select all

setTimeout('getRtgsElm()', 400); // calls getRtgsElm() at 400 milliseconds after page loads
Try include the script asynchronous:

Code: Select all

<script async src="ratingfiles/ratings.js"></script>
I not have experience with SQLite, but from what i read on internet:
The access time for SQLite will appear faster at first instance, but this is with a small number of users online. SQLite uses a very simplistic access algorithm, its fast but does not handle concurrency.

As the database starts to grow, and the amount of simultaneous access it will start to suffer. The way servers handle multiple requests is completely different and way more complex and optimized for high concurrency. For example, SQLite will lock the whole table if an update is going on, and queue the orders.
So, not sure if the sqlite is the problem, but I understand that SQLite not support using of multiple database and queries same time.
Try test it with the "txt" or "mysql" options to see if it works faster.

- MySQL, particularly when using the InnoDB storage engine, will scale much better than SQLite; especially when there are lots (thousand) of records.

Alecos Posts: 18
Thanks for the short explanation. I now know the mechanism of sqlite query... and the Ajax call is already in asynchronous mode since the third parameter passed is TRUE.

Thanks for your patience.