Public function fetch ($ SQL, $ searchData = array (), $ dataMode = PDO: FETCH_ASSOC, $ preType = array (PDO: ATTR_CURSOR => PDO: CURSOR_FWDONLY )){ If ($ SQL ){ $ SQL. = 'limit 1 '; $ PdoStatement = $ this-> pdo-> prepare ($ SQL, $ preType ); $ PdoStatement-> execute ($ searchData ); Return $ data = $ pdoStatement-> fetch ($ dataMode ); } Else { Return false; } } Public function fetchAll ($ SQL, $ searchData = array (), $ limit = array (0, 10), $ dataMode = PDO: FETCH_ASSOC, $ preType = array (PDO :: ATTR_CURSOR => PDO: CURSOR_FWDONLY )){ If ($ SQL ){ $ SQL. = 'limit'. (int) $ limit [0]. ','. (intval ($ limit [1])> 0? Intval ($ limit [1]): 10 ); $ PdoStatement = $ this-> pdo-> prepare ($ SQL, $ preType ); $ PdoStatement-> execute ($ searchData ); Return $ data = $ pdoStatement-> fetchAll ($ dataMode ); } Else { Return false; } } Public function insert ($ tableName, $ data, $ returnInsertId = false, $ replace = false ){ If (! Empty ($ tableName) & count ($ data)> 0 ){ $ SQL = $ replace? 'Replace into': 'insert '; List ($ setSql, $ mapData) = $ this-> FDFields ($ data ); $ SQL. = $ tableName. 'set'. $ setSql; $ PdoStatement = $ this-> pdo-> prepare ($ SQL, array (PDO: ATTR_CURSOR => PDO: CURSOR_FWDONLY )); $ ExecRet = $ pdoStatement-> execute ($ mapData ); Return $ execRet? ($ ReturnInsertId? $ This-> pdo-> lastInsertId (): $ execRet): false; } Else { Return false; } } Public function update ($ tableName, $ data, $ condition, $ mapData = array (), $ returnRowCount = true ){ If (! Empty ($ tableName) & count ($ data)> 0 ){ $ SQL = 'update'. $ tableName. 'set '; List ($ setSql, $ mapSetData) = $ this-> FDFields ($ data ); $ SQL. = $ setSql; $ MapData = array_merge ($ mapData, $ mapSetData ); List ($ where, $ mapData) = $ this-> FDCondition ($ condition, $ mapData ); $ SQL. = $ where? 'Where'. $ WHERE :''; $ PdoStatement = $ this-> pdo-> prepare ($ SQL, array (PDO: ATTR_CURSOR => PDO: CURSOR_FWDONLY )); $ ExecRet = $ pdoStatement-> execute ($ mapData ); Return $ execRet? ($ ReturnRowCount? $ PdoStatement-> rowCount (): $ execRet): false; } Else { Return false; } } Public function delete ($ tableName, $ condition, $ mapData = array ()){ If (! Empty ($ tableName) & $ condition ){ $ SQL = 'delete from'. $ tableName; List ($ where, $ mapData) = $ this-> FDCondition ($ condition, $ mapData ); $ SQL. = $ where? 'Where'. $ WHERE :''; $ PdoStatement = $ this-> pdo-> prepare ($ SQL, array (PDO: ATTR_CURSOR => PDO: CURSOR_FWDONLY )); $ ExecRet = $ pdoStatement-> execute ($ mapData ); Return $ execRet; } } |