WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.12.x) »
  • General Help & Support »
  • Database access
  • Print
Pages: [1]   Go Down

Author Topic: Database access  (Read 5676 times)

Offline sixis

  • Posts: 10
Database access
« on: March 19, 2020, 09:32:57 PM »
After updating to 2.12.2 i cant access the database in the code section as before (2.8.1)

Maybe someone has in idea whats wrong with my code.

mysqli_query ("UPDATE tablename SET column ='$xxxxxxx' WHERE ID=1") or die ("MySQL-Fehler: " . mysqli_error());

old code that worked:

mysql_query ("UPDATE tablename SET column ='$xxxxxxx' WHERE ID=1") or die ("MySQL-Fehler: " . mysql_error());
Logged

Offline Ruud

  • Posts: 3671
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Database access
« Reply #1 on: March 19, 2020, 10:31:50 PM »
WB2.8.1 used MySQL, where the current WB versions (and PHP) use MySQLi.
mysqli_query() needs the handle that was created when the connection to the database was made.

WB has the $database class you can use. The correct way would be:
Code: [Select]
<?php 
$database
->query("YOUR QUERY");
// if you want to crash on errors (not recommended)
if($database->is_error()) die("Error: ".$database->get_error();

Logged
Dev4me - WebsiteBaker modules - WBhelp.org

Offline sixis

  • Posts: 10
Re: Database access
« Reply #2 on: March 20, 2020, 09:37:55 AM »
You are my hero  :-D
Thank you

Updating works nice :-)

I realize i have to learn a lot e.g. how to readout the table

$database->query("SELECT * FROM wb_users WHERE username = test");
while ($data = mysqli_fetch_assoc($database))
{$mailadress=$data[email];
echo $mailadress;
}
Logged

Offline dbs

  • Betatester
  • **
  • Posts: 8914
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: Database access
« Reply #3 on: March 20, 2020, 10:01:46 AM »
You should have a look into core modules (like news, form, code) to learn.
E.g. to read a single result you can use
Code: [Select]
$database->get_one('SELECT ...
Logged
https://onkel-franky.de

Offline sixis

  • Posts: 10
Re: Database access
« Reply #4 on: March 20, 2020, 10:56:23 AM »
yeaaaa

from the code module section i succeeded whith this:

//Auslesen
$query = "SELECT * FROM tablename WHERE ID = 1";
$get_content = $database->query($query);

$content = $get_content->fetchRow(MYSQLI_ASSOC);
$content = ($content['email']);  // \htmlspecialchars

echo $content;


THANK YOU ALL
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.12.x) »
  • General Help & Support »
  • Database access
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2