WebsiteBaker Support (2.8.x) > Templates, Menus & Design
Using SQL in 2.8.3
richwingerter:
I have an older version of Website Baker running and I am porting to the latest version, but I'm having trouble getting access to the MySQL DB. I was able to get it before by putting some code into each page like this:
--- Code: ---require_once(WB_PATH.'/config.php');
require_once(WB_PATH.'/manager/main.functions.php');
require_once(WB_PATH.'/framework/class.database.php');
load_website_config();
--- End code ---
I'd like to get access to the SQL functions in the latest version. Has anyone tried this and can help me?
Thanks!
Ruud:
Some strange things happening here...
The first require cannot work.
WB_PATH is only set in the config.php that is required_once. So if WB_PATH is defined, the config is already loaded making that line useless.
If not, it will effectively load [SERVER_ROOT]/config.php which is very unlikely to succeed.
The second require is not part of WB, so no telling what will happen there.
The third require is useless too. The same thing as the first one, if WB_PATH is defined, config.php is loaded and the WB initialize script is called too. With that the database classes are already loaded.
The command "load_website_config()" is not a WB function. No telling what should happen there.
So for an external script, just load config.php (make shure your script knows where it is located).
After that, the $database functions are available to that script.
richwingerter:
This was internal to a page in Website Baker. That is, I went into the Administrator, went to Pages, edited a (code) page, and put that code into the page. So, that would mean that WB_PATH should be set. I think that in the version I was working with I was not able to get any database calls to work without adding these lines within the page.
The more basic question is that I want to execute a SQL call inside the page. So, on the page I would have something like:
--- Code: ---$mysql = new mysql;
$sql = "SELECT ...";
$res = $mysql->query($sql);
--- End code ---
etc.
Should this work just by adding that code within a page?
Thanks!
Ruud:
--- Quote from: richwingerter on September 30, 2016, 12:57:22 AM ---Should this work just by adding that code within a page?
--- End quote ---
No. You should use the existing $database functions. (note that the code is executed in a local function scope)
I would suggest to look through other modules code first to learn a bit more about the WB stuctures.
If that is not clear to you, I would strongly advise not to try this kind of php coding yourself.
richwingerter:
That's what I expected, that it wouldn't work because it's in local scope and I'd have to bring in the definitions to get it working. This worked find for the previous version of Website Baker, because I was able to require the database classes. But I'm not sure where to find those pieces for the current version.
In the current distribution there's a mailing_list.phps file. It uses this call:
--- Code: ---$mysql = mysqli_connect('localhost', 'username', 'password');
mysqli_select_db($mysql, 'mydb');
etc.
--- End code ---
This is out of context, so I don't know if it's also running in local scope. It does not appear to have any dependencies for mysqli functions.
I tested:
--- Code: ---$db = mysqli_connect( my parameters);
if(!$db) {
die("Could not connect: " . $mysqli_error());
}
--- End code ---
(Where my parameters were 'localhost' and the name/password I use to log in to the database through phpMyAdmin.)
All I got was:
--- Code: ---Could not connect:
--- End code ---
It's not getting the library.
Do you have a reference to documentation or a specific module that works?
Navigation
[0] Message Index
[#] Next page
Go to full version