php - query inside a pdo while loop -
Hi, I think I have designed my PDS mysql class worse, because I have some time within Can not put a query in the loop of another query because the new query inside the loop erases the old one, is there an easy way to fix it?
I have also really used the old style php / mysql where you create a query, then assign that query within the fetch ($ query) that you do not do with PDO I am in disarray and it is going to annoy me for a long time.
My code is cut in the relevant parts
class mysql {// query counter public $ counter = 0; // database connection public $ databases; // statement handler public $ STH; // public $ queries = '' Store all queries for debugging; Public function __ composition ($ database_host, $ database_true, $ database_password, $ database_db) {$ options = array (PDO :: MySQL_ATTR_INIT_COMMAND = & gt; 'SET NAMES utf8',); $ This- & gt; Database = New PDO ("mysql: host = $ database_host; dbname = $ database_db", $ database_true, $ database_password, $ option); $ This- & gt; Database-> Set attribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION); } // A plain query public function pquery ($ sql, $ page = null) {global $ core; {$ This-> STH = $ this- & gt; Database-> Try ($ sql) to try; $ This- & gt; Counter ++; $ This- & gt; Query = "& Lt; br / & gt; $ sql"; Return $ this - & gt; STH- & gt; carry about (); } Hold (exception $ E) {$ core-> The message ("Something went wrong. The administrator will be notified and the idiots will be punished because I am a wicked ruler ... I am sure that I will soon decide.", NULL, 1); $ This- & gt; Pdo_error ($ e-> getMessage (), $ page, $ sql); }} // main SQL query function public function sqlquery ($ sql, $ objects = array (), $ page = null, $ referrer = null) {global $ core; {$ This-> STH = $ this- & gt; Database-> Try ($ sql) to try; Foreach ($ k => Objects as $ p) {// +1 is required because the array starts at 0? Placeholders start with PDO in 1 (If_Animeric ($ p)) {// We need to do this or other decimal always end 'x.00', there is no decimal check in the peda, weird if ($ This-> include_dynamic ($ p) == true) {$ this-> STH- & gt; Byte value ($ k + 1, $ p, PDO :: PARAM_STR); } And {$ this- & gt; STH- & gt; Byte value ($ k + 1, (int) $ p, PDO :: PARAM_INT); }} And {$ this-> STH- & gt; Byte value ($ k + 1, $ p, PDO :: PARAM_STR); }} $ This-> Counter ++; $ This- & gt; Query = "& Lt; br / & gt; $ sql"; Return $ this - & gt; STH- & gt; carry about (); } Hold (exception $ E) {$ core-> The message ("Something went wrong. The administrator will be notified and the idiots will be punished because I am a wicked ruler ... I am sure that I will soon decide.", NULL, 1); $ This- & gt; Pdo_error ($ e-> getMessage (), $ page, $ sql, $ referrer); }} Public Function Fetch () {$ this- & gt; STH- & gt; Settet Mode (PDO :: FETCH_ASSOC); Return $ this - & gt; STH- & gt; Fetch (); }
Comments
Post a Comment