📜 ⬆️ ⬇️

PEAR DB emulator by PDO with some functionality extension or simple add-on over PDO

Good time to all!
As promised earlier , and also at the request of some users of Habr, I upload a new version of the PEAR DB emulator made on the basis of PDO and successfully working with new versions of PHP. You can download it here (from the Code section, the trunk branch) or here , as well as using snv
like this: svn checkout svn://svn.code.sf.net/p/peardb2pdo/code/trunk peardb2pdo-code
or so: svn checkout svn.code.sf.net/p/peardb2pdo/code/trunk peardb2pdo-code

If desired, the code can be taken as a basis for creating new projects where you do not want to use heavy add-ons above the base.

License: GNU General Public License .

Further more ...
')
As written in the title, everything is rewritten under PDO and is designed to work with the latest versions of PHP.
The code was tested on one (not yet completed) project. It works like normal. A couple of functions are specific to MySQL, but if you want, you can get rid of the specifics (see the $ server class property). Added the possibility of parameterized queries, well, and other little things that will be clear from the examples below and the class code, I think anyone will figure it out. Suggestions and amendments are welcome. Judging by the response to the first article, the problem of “dismounting” with PEAR DB is relevant. Perhaps it was worthwhile to still test and polish, but people are in a hurry, they ask to put it out sooner, so I propose to do it together with those who find it interesting and necessary.

Comments / suggestions / corrections request in a personal or in the discussion on the page of the project with pieces of code that you think should be corrected or supplemented.

Following are some examples:

1.Connection
 require_once 'includes/classes/classERROR.php'; require_once 'includes/classes/classMYSQLPDO.php'; $db = new DB(); $show_errors = false; $stop_after_error = false; $on_error_rollback = true; if(!$db->connect('localhost','user','pass', 'database','table_preffix_',$show_errors , $stop_after_error, $on_error_rollback )) { echo "DB Connect Error!"; exit(); } 


2. Parameterized query - Option 1:
 $params['person_id']=array('57FA56C2',8); $params['nickname']=array('USER',4); print_r($db->getAll("select * from persons WHERE person_id=:person_id and nickname=:nickname",$params)); echo "  : ".$db->fcount(); echo "  : ".$db->rcount(); //      $params['person_id']=array('2457A5F',7); $params['nickname']=array('ADMIN',5); print_r($db->repeat($params)); echo "  : ".$db->fcount(); echo "  : ".$db->rcount(); 


3. Parameterized query - Option 2:
 print_r($db->getRow("select * from persons WHERE person_id=? LIMIT 1",array('57FD56C2'))); echo "  : ".$db->fcount(); 


The parameter: $ alias in functions allows dividing SQL queries into sessions (for cases when it is necessary to combine several parameterized queries, for example, in one cycle (so that the parameters and the results of certain functions are not mixed).

I hope not all tired. The remaining features are quite obvious and understandable from the code. Please do not kick much and if you want to help bring the code to mind because The need for it, judging by the letters with the request to lay out, really is and people are in a hurry. If errors are found, please notify the author.

Thanks for attention. I hope someone helped. If not, just look at my pictures :) there it will help overcome relax and forget :)
Sincerely, Mikhail Chervonenko / Mikhail Tchervonenko.

ps The class of error handling is laid out in the old version with all the flaws, it has not yet reached its hands, and perhaps in the near future it will not be reached (personally, it suits me in this version as it is). I do not see a special need to change something in it, but if someone improves it, I will gladly post it in the project.

Source: https://habr.com/ru/post/142954/


All Articles