The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
DB.php edits by Faguss - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: DB.php edits by Faguss (/showthread.php?tid=586)



DB.php edits by Faguss - faguss - 06-06-2017

EDIT: I've changed this topic to be a list of things I've added instead of just about one function.

====

https://pastebin.com/Jp2EbDTw
Based on the version by @plb . My changes to his code are listed there.

30 - charset=utf8 added because of this issue

50 - results are cleaned before every query

195 - delete() won't work if argument is empty

204-221 - insert() can add multiple records

202, 223-232 - added optional argument for insert() so that it can update records on duplicate id

238 - column names are wrapped in grave accents in update()

239-252 - optionally condition array may be passed to update() instead of record id

265 - added optional argument for first() which works in the same way as for results() (aka returns array instead of an object). Also if there are no results the function will return empty array.

300-309 - added cell() for getting single field out of first record


DB.php edits by Faguss - mudmin - 06-06-2017

You can also do

$query->results(true) on your db query and it will create an array instead of an object


DB.php edits by Faguss - faguss - 06-22-2017

Let's talk about
Code:
results(true)
as well. Variables with results are now cleaned before every query so I can do this:

Code:
$array = $db->query($sql,$input)->results(true);

instead of:

Code:
$array = !$db->query($sql,$input)->error() ? $db->results(true) : [];

https://pastebin.com/Jp2EbDTw (line 50)


DB.php edits by Faguss - faguss - 07-14-2017

I should have started a more general thread. Instead, I'm repurposing this one. Anyway, there's a new function cell() for getting one field out of the first result. Examples:

Code:
$bio = $db->cell("profiles.bio",1);
Code:
if (isset($bio)) echo $bio;

Code:
$number = $db->cell("users.COUNT(*)",["TIMESTAMPDIFF(DAY,join_date,CURRENT_TIMESTAMP)","<",30]);
Code:
if (!empty($number)) echo "$number new user".($number!=1?"s":"")." recently";



DB.php edits by Faguss - picassoo - 07-16-2017

wow, nice... where you update your project ? can you send me or post the link pleasee ?


DB.php edits by Faguss - faguss - 07-16-2017

DB.php code is in the pastebin link: https://pastebin.com/Jp2EbDTw