Jump to content

Could someone help me rewrite a SQL query?


yggdrasil

Recommended Posts

Could someone be so kind and help me rewrite my SQL query?

 

 

If I was reading correctly, the SQL function that still works in v7 may be removed from future versions. To add to the injury, you are supposed to use the mysqli function now as the current one is depcreated, but I tested mysqli and it does not work in v7, straight error.

 

So, I guess I’m forced to use the new SQL helper approach with WHMCS. I cannot get make sense of the WHMCS documentation example because they are putting complicated examples and I just a simple basic table query.

 

This is what I have currently in PHP inside a template and it works. It’s simple and nice and I like it. I would love to keep it like this but I don’t seem to have an option. I need to move to the correct WHMCS way or it will be rendered useless in the future. :(

 

EDIT: CloudFlare deleted my post and blocked it, twice. !!!

 

Please see the attached text file because the horrible CloudFlare system is blocking me from posting the code. :oops:

 

EDIT AGAIN: The upload system in the WHMCS forum does not work. :mad:

 

Ok here it is: :idea:

http://pastebin.com/EnTmTSKr

Link to comment
Share on other sites

Could someone be so kind and help me rewrite my SQL query?

If I was reading correctly, the SQL function that still works in v7 may be removed from future versions.

yes, they told us that when v6 was launched in 2015... yet here we are two years later and you can still use it.... I would imagine it'll be removed in v8, but who knows. :?:

 

To add to the injury, you are supposed to use the mysqli function now as the current one is deprecated, but I tested mysqli and it does not work in v7, straight error.

So, I guess I’m forced to use the new SQL helper approach with WHMCS. I cannot get make sense of the WHMCS documentation example because they are putting complicated examples and I just a simple basic table query.

This is what I have currently in PHP inside a template and it works. It’s simple and nice and I like it. I would love to keep it like this but I don’t seem to have an option. I need to move to the correct WHMCS way or it will be rendered useless in the future. :(

to rewrite the query in an action hook, you would just do this...

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_ygg_domain($vars) 
{
   $ygg_domain = Capsule::table('tbldomains')
               ->where('id','1')
               ->where('userid','1')
               ->value('domain');

   return array("ygg_domain" => $ygg_domain);                
}
add_hook("ClientAreaPage", 1, "hook_ygg_domain");
?>

i've got rid of the while loop because, if you give the query conditions of both ID and userID, the answer will be just one value (the domain name or NULL) - it won't be an array.

btw - if it were going to be an array, they you'd use get() and work your way through the loop.. but that's for another day.

 

as it stands, the hook will return a Smarty variable back to the template, {$ygg_domain}, that will either contain the domain name found in the query, or if one wasn't found, the value will be null.

 

so you've got additional options open to you...

 

1. you could do your checks in the hook as to the Error/Great conditions, and adjust the value returned to the template accordingly...

2. or just do it in the template based on the query result returned - though I think the "correct" way would be to do it in the hook...

3. currently the variable is available to all client area pages - but you could tweak the hook so it only worked for one particular templatefile if it's only needed there.

Link to comment
Share on other sites

Thank you, I will give it a shoot. I think the SQL code is like that because I just re-use the same query for other things and sometimes I need to get more than one result at once from the same query (array?). I understand its not very fancy but it worked so far in order to basically do 2 things:

 

1. Proceed with another code or action with the result.

2. Otherwise proceed with another code or fail hard.

 

Mostly, the thing I do is the same over and over again. Just take a value and compare it to something or use it in the template. I'm not a developer so there are probably tons of mistakes I do which I'm not aware. This is also why I didn't moved them to a hook either, because I don't know how to pass them to the templates and back.

 

Passing something to the template seems easy, but what if you need to compare something with the template and go back to the PHP code and or execute another one? I'm sure it can be done with hooks but so far it was just easier at least in my mind if the code was in the same template in which the data is manipulated. Not fancy, probably not secure, but it worked. I'm not even sure if this possible, to pass data back to the hook because its only executed once, or maybe the hook is supposed to read all the template variables first. The problem is that sometimes you require user actions and execute a code based on that. You can't do that with a hook. The user needs to send a form or do something first.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated