The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB.php edits by Faguss
#1
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
  Reply
#2
You can also do

$query->results(true) on your db query and it will create an array instead of an object
  Reply
#3
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)
  Reply
#4
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";
  Reply
#5
wow, nice... where you update your project ? can you send me or post the link pleasee ?
  Reply
#6
DB.php code is in the pastebin link: https://pastebin.com/Jp2EbDTw
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)