Author Topic: Database access  (Read 331 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());

Offline Ruud

  • Posts: 3660
  • 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();


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;
}

Offline dbs

  • Betatester
  • **
  • Posts: 8402
  • 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 ...

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