PHP quizz with pdo

PHP quizz with pdo

de către Didier BERNARD-
Număr de răspunsuri: 5

Hello, and thanx in advance for your answers.

A would like to create a quizz with php code using PDO for accessing sqlite database.

I create a php code runner quizz, for the database, i add in Template params:

{"database_name":"video.db"}

all works fine, but if i try accessing with php PDO, i got this error:

"Fatal error: Uncaught Error: Class 'PDO' not found in __tester__.php"

is it impossible to have a pdo usage in php quizz ?

Ca răspuns la Didier BERNARD

Re: PHP quizz with pdo

de către Richard Lobb-

I've never used PDP PDO, but I don't know of any reason why it won't work from CodeRunner. The error message seems to suggest that PDO isn't actually installed on your Jobe server, though it should be there by default. Do you now anything about your Jobe server, such as whether it's a standard install and what the base OS is (e.g. Ubuntu-20)? If you didn't built it yourself, you could ask whoever did to check whether PDO is installed?


Ca răspuns la Didier BERNARD

Re: PHP quizz with pdo

de către Didier BERNARD-

ok, i reply to myself. :)

so to make it works, i changed the file application/libraries/php_task.php on the jobe server, and replace the line:

$this->default_params['interpreterargs'] = array('--no-php-ini');

by

$this->default_params['interpreterargs'] = array('--no-php-ini -d extension=pdo.so -d extension=pdo_sqlite.so -d extension=json.so');


Ca răspuns la Didier BERNARD

Re: PHP quizz with pdo

de către Richard Lobb-

Good that you've found a solution, but I'd recommend against editing the Jobe source code as it creates on-going maintenance problems every time a new version is released.

What you've set is the default interpreter args, but you can set explicit interpreter args within the CodeRunner question itself and these will override the default. Customise your question, open the Advanced Customisation panel and in the Sandbox > Parameters field enter what you want, using JSON, e.g.

{"interpreterargs": ["-d blah"]}

Or better, create a new question type and make that change there - then all your questions that need those extensions can be of that new type.

Mind you, I'm not quite sure why you needed to make those changes anyway. The required extensions are clearly all there, just not being used by default. Perhaps as a consequence of the --no-php-ini interpreter arg? Unfortunately I can't remember why I chose to disable php-ini in PHP questions - perhaps it opens a security hole? In any case it might be interesting to try setting the interpreterargs to the empty list to see if that also enables all the missing extensions?

Ca răspuns la Richard Lobb

Re: PHP quizz with pdo

de către Didier BERNARD-

Ok, i did it (with the sandbox parameters), and it works and it's less "ugly".

:)

Thanx, great job.

Ca răspuns la Didier BERNARD

Re: PHP quizz with pdo

de către Ping Zhang-
Hi Didier,

I only find you have use PHP + PDO. Have you tried "INSERT"? I got HY000 error and believe it is the permission issue of db file. If you know how to adjust the permission, many thanks!

Thanks,

Ping