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
/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
Help to query the database
#1
I'm looking at the manual, but I think not all understand as it is, for example, we find the following documentation:

$director_id = 1;
$query = $db->query("SELECT * FROM camps WHERE director_id = ?", array($director_id));
$x = $query->results();


Then, as I do to show results, ie in this case I want a list of "names" in "camps" ... I just want to know how to do the "echo" or as I show in html the results?

I propose to make a manual like this.

Is costing me a lot of work interact with the database and predefined classes, I really do not know how I am suffering.

Most rookies just want to show something that is already in the database, send the information to achieve, but I can not show it.

I do not want to use functions because it is more difficult for me, I just want a simple query and display the results.

Could you help me?
  Reply
#2
We are creating a wiki to better document using userspice.

That said, one thing to note...there is no obligation to use our database class. If you add your own (as long as you don't call it DB), it will work just fine (even if it is on the same page) with ours.

That said.

In the example above...

Code:
$query = $db->query(“SELECT * FROM camps WHERE director_id = ?”, array($director_id));
Note that you don't HAVE to assign a variable like $query in front of it. I tend to do it to make things a little more readable. Essentially, $db->query gives you the opportunity to run ANY query in mysql.

So....what do you do with that query? You have options. That entire query is now called $query.

You can get ALL the information back by
Code:
$x = $query->results();

Or just the first response if you do
Code:
$x = $query->first();

I think what you're asking though is how do you get the info inside back. It's super easy.

It is a good idea to test your results by doing
dump($x); //gives you the full list of everything you got back.

Then if you have a column named 'name', just do

$x->name;

To echo it you would do something like this.
Welcome to our website, <?=$x->name?>. It's great to have you.
  Reply
#3
Thank you very much for the reply and the great help ... I said he was very interested in integrating "MeekroDB" in the project but to try out errors everywhere since the classe is called "DB" attempt to change the classes by another name but still I did not work, I would love to integrate but could not, it was a great frustration because it would have been helpful.

By chance you know this class and if so, have an idea of how to integrate it without affecting the operation of "userspice"?

Or how it could change by a replacement of "DB" by another word or something?
  Reply
#4
It's easy to include that class.

Download Meekro 2.3

Copy it to the classes folder.

Edit line 20 in the meekro class and replace class DB{ with class DB2{

Put in your database credentials on lines 22-25.

Find/replace with in the rest of the class...

Find:
DB::

Replace:
DB2::

Edit users/init.php around line 56 to add your

require_once $abs_us_root.$us_url_root.'users/classes/meekrodb.2.3.class.php';



You're good to go. Everything should work fine and you can use your meekro class for your stuff and let our db class do its thing.

  Reply
#5
This really worked, THANK YOU!

Lanzo some mistakes but is solved with the following:

If someone else wants to do this, you must change into "meekrodb.2.3.class.php" line 161 the following:

$db_class_vars = get_class_vars('DB'); -> $db_class_vars = get_class_vars('DB2');

  Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)