Jump to content

requinix

Administrators
  • Posts

    14,237
  • Joined

  • Last visited

  • Days Won

    369

Community Answers

  1. requinix's post in Unable to attach an external RDS instance to Elastic Beanstalk using CLI was marked as the answer   
    The UI is what they call the "console"... and that ambiguity is why I called it the UI. You know, the main website for managing stuff.
     
    - Document root is a configuration thing. Or just say /var/www
    - Auto-generated security group? Don't. Make a standalone security group for these instances and have each use it.
    - Copy database is a configuration thing. Should be just a matter of a post-installation command to dump the RDS data into the local MySQL like

    mysqldump --options... and -h -u -p for the rds instance | mysql -h -u -p for the local instance- Hostname and credentials are also a configuration thing 
    The CodeDeploy settings go into their own file, your application settings go into their own file(s) however they're supposed to work.
  2. requinix's post in getting data from multiple tables with sum in a single result set was marked as the answer   
    Well now you're changing the requirements, but okay.
     
    First we have to fix your query to be better and more suitable for a view. A view makes it much easier to use this query, and in other places.

    SELECT r.invoice_id, r.customer, r.paid_amount, r.mode, r.ref_no, r.paid_date, r.comments, l.company, 'Income' AS IncomeOrExpense FROM receipt r INNER JOIN leads l ON r.customer=l.id UNION ALL SELECT p.invoice_id, p.vendor, p.paid_amount, p.mode, p.ref_no, p.paid_date, p.comments, v.name, 'Expense' FROM payments p INNER JOIN vendor v ON p.vendor=v.id UNION ALL SELECT e.eid, e.user, e.paid_amount, e.mode, e.ref_no, e.paid_date, e.comments, ???, 'Expense' FROM expense e INNER JOIN ??? Then put it into the view.
    CREATE VIEW pick_a_name AS SELECT...Now make a new query to select from the view and do the grouping and sorting.
    SELECT YEAR(v.paid_date) AS Yr, MONTHNAME(v.paid_date) AS Month, SUM(IF(v.IncomeOrExpense = 'Income', v.paid_amount, 0)) AS Income, SUM(IF(v.IncomeOrExpense = 'Expense', v.paid_amount, 0)) AS Expense FROM pick_a_name v GROUP BY Yr, Month ORDER BY Yr DESC, Month DESC
  3. requinix's post in SQL DB Sending old results was marked as the answer   
    Add a little bit to the code:

    <?php $query = $conn->prepare("SELECT ID, username, fname, lname, email, tokens, NOW() FROM `users` WHERE ID = ?"); $query->bind_param("s",$_SESSION['ID']); $query->execute(); $query->bind_result($ID, $username, $firstname, $lastname, $email, $tokens, $now); $query->fetch(); $query->close(); ?> <p class="my-account-p-padded"> <br> Username: <?php echo $username; ?><br> First Name: <?php echo $firstname; ?><br> Last Name: <?php echo $lastname; ?><br> Account Tokens: <?php echo $tokens; ?> <a href="javascript:void(0)" onclick="showlightbox();" id="addmoretokensbtn">Add More</a><br> PHP Time: <?php echo date("Y-m-d H:i:s"); ?><br> DB Time: <?php echo $now; ?><br> <span id="explain" style="display: none;">(Scroll Up to see screen)</span> </p>Do you see the two times changing?
  4. requinix's post in Apache/2.4.27 (Win64) PHP/7.1.8 PDO was marked as the answer   
    Seems fine. Any startup errors? What is "blank"?
  5. requinix's post in Insering Multple files was marked as the answer   
    > yes I am trying to use that
    Well you can't. There is nothing in $_POST that can help you with file uploads. Everything is in $_FILES.
  6. requinix's post in running another client side program with in my HTML was marked as the answer   
    To the question you asked, kinda. To the question I think you're trying to ask, no.
     
    It is possible for a web server to run things like "programs". They run on the server itself. It is not possible for the server to cause a program to run on the client. That would be really, really bad.
     
    There are workarounds for very specific environments, like Windows domains when people are using Internet Explorer/Edge, not to mention completely unrelated mechanisms like a network-local server remotely running commands on the client machine itself, but that's something else.
  7. requinix's post in A Function Parameter That Takes In A Constant, Can It Always Take In A Variable Unless It Needs A Handle ? was marked as the answer   
    The only difference that matters here between a variable and a constant is that a variable can be modified and a constant cannot. If something does not need to modify a value then it doesn't matter which one you use.
  8. requinix's post in What Is An Element In Php ? was marked as the answer   
    That's right. 

    I was responding to the "3 could mean anything" comment. It does not mean anything. The manual specifically says the function tells you "the number of elements in array_or_countable". 

    I mean exactly what the words themselves mean. In code you could say
    count(array_keys($array)) == count(array_values($array))A bit of a recursive definition, admittedly.
  9. requinix's post in Relinquishing memory in WHILE loop was marked as the answer   
    In general you want a buffered query: it's much faster, frees up your connection for another query, and releases database resources. An unbuffered query is the opposite of that, but uses far less memory for large resultsets. 
    The second point in there is where the closed cursor comes in. Basically, a resultset needs to reach the end* so that both sides of the connection know the data is read and the server can do other stuff. IIRC closeCursor()-type functionality guarantees that the resultset was fully read and then immediately releases some client resources (which would have been freed normally eventually anyways).
    fetchAll() reads everything (either from memory or from the server) and gives you an array, so one way or another the resultset is fully used up. fetch() gives you just one row so you're still subject to un/buffered query rules.
     
    And yes, a distinction between buffered and unbuffered resultsets is common in client APIs for databases. (The server doesn't know or care either way.)
     
    * Past the end, actually. The client doesn't know it's at the end until it fails to read another row. The row count is actually maintained by the client as a counter from it reading rows - it's not sent by the server with the results.
  10. requinix's post in htaccess hotlink filter with remote "readfile" was marked as the answer   
    Whoever wrote those didn't quite understand what they were doing. You only need one for a domain.

    RewriteEngine on RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mydomainhere/ [NC] RewriteCond %{HTTP_REFERER} !^https?://(www\.)?otherdomain/ [NC] RewriteCond %{HTTP_REFERER} !^$ RewriteRule \.(gif|jpg|png)$ - [F]The third line is to allow direct access in the browser, ie. copying and pasting the URL into the address bar directly.
  11. requinix's post in Why Did Session Object Destruction Failed ? was marked as the answer   
    It happens when the session data could not be deleted. You're probably using regular session files, so that means the file couldn't be deleted: it may have been already (somehow), or maybe permissions were messed up, or perhaps the file was locked because PHP was still using it (I don't know about that one).
     
    Adding session_regenerate_id() will only cover up the problem by switching the session ID to something else just before you delete it. Extra work for no gain.
  12. requinix's post in Dealing with Triggers... was marked as the answer   
    Yeah, that's not even close to valid syntax. I linked the docs in the other thread.
     
    If your original query was

    update a_players p join wp_terms t set p.wpID = t.term_id where t.slug = p.wpSlugand NEW.term_id and NEW.slug are both things, then
    update a_players set wpID = NEW.term_id where wpSlug = NEW.slugSince wp_terms.term_id is an auto_increment-ed primary key you'll have to run this AFTER the insert so you can get its value. 
    If you describe it that simply, yes. What I'm saying is that if you describe it precisely, as we've both done a few times now, it no longer is what you want. The end result is correct but the process to get there is not.
  13. requinix's post in file system performance; how many files in one dir was marked as the answer   
    Depends on the filesystem. ext4 (most common?) doesn't have a limit per directory. However directories themselves take space to store a list of their contents, and unless the system sorts directory entries (?) looking for a file requires scanning the directory list for it.
     
    It might be antiquated now but if you know the filename from another source then I'd partition. I tend to generate hex filenames and take the first two bytes' worth as two subdirectories.

    /01/23/0123456789abcdef.extAssuming an even distribution, by the time you've filled each second-level directory with 256 files you've stored 16M total. More than enough.
  14. requinix's post in Question On The Variable (Array Value) was marked as the answer   
    It holds each value from the $colors array, one at a time.
  15. requinix's post in Scary Warning? was marked as the answer   
    PHP Freaks is now brought to you by common sense and the letter A.
  16. requinix's post in Execute shell script in PHP was marked as the answer   
    0777 on the script means anyone can read, write, or execute the script.
     
    If you're absolutely sure that the script is safe to execute - no vulnerabilities - then you can setuid it to cause it to be run in its owner's account instead of Apache. But there's no guarantee the system will honor that.
     
    Otherwise it would be great if you could change things so that the directory it needs to write to is also owned by Apache. Means your personal account couldn't change anything inside without sudo but the script could run without fiddling with permissions.
     
    Worst case, set 0777 on the directory so that anyone can read the directory, write new files in it, or traverse the directory.
     

    It says what?
  17. requinix's post in PHP startup warning on amazon aws was marked as the answer   
    Check the PHP configuration used with Apache. You at least display_errors=off, so set error_log to somewhere appropriate, restart Apache, and try again. 
    But the problem is probably a missing mbstring.
     

    Depends on the configuration. It could. Personally I wouldn't use a separate configuration for the two. 

    You have php-fpm installed, which works differently from a regular Apache module. Now you need to look at its configuration to see what it has. The logs would probably be in /var/log/php-fpm.
  18. requinix's post in PHP get cURL response value as variable was marked as the answer   
    No, that's not the problem.
     
    I skipped the first half of your post and went straight to the second part, where you said you had some JSON and couldn't get the success value. I didn't notice that you don't actually have the JSON.
     
    cURL will output stuff by default. That is what your code is doing now: outputting the JSON to the browser. That's how you're able to see what it is. Instead, you need to get that output into a variable. You do it with the CURLOPT_RETURNTRANSFER option.

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);When that is set, the return value from curl_exec (which you have as $ch_result) will be the response as a string. The JSON. 
    You then need to decode that variable. Not $ch, which is just a cURL identifier for doing cURL operations, and useless once you've curl_close()d it. Which, by the way, you need to do if you aren't doing it already.

    $json = json_decode($ch_result);And now you can properly use var_dump to see the value you want:
    var_dump($json->success);It will say either bool(true) or bool(false) - anything else probably means there's still an error in your code. 
     
    If you think something should be true/false and you get null then don't just roll with it. Find out why it's doing that and not doing what you expect.
  19. requinix's post in Upgrading Php4 to 5 & mysql to mysqli - Warning: mysqli_query() expects parameter 1 to be mysqli, null given was marked as the answer   
    If you're upgrading then you might as well go for PHP 7: 5.6 is the last of the 5.x series (there is no 6.x) and is no longer receiving feature updates. 7.0 is out, 7.1 is out, and 7.2 is coming out fairly soon. The good news is that 5->7 has fewer big changes than 4->5.
     
    Anyway, variables defined outside of a function are not available inside of a function. Files themselves don't have scopes (they kinda do but nothing relevant here) so that's not it.
    Not that you've actually said what your problem is - just a vague "it doesn't work".
     
    If you want a quick way to get a mysqli object (which is what $mysqli actually is) then you can do

    function db() { static $link = null; if (!$link) { $link = new mysqli('localhost', 'username', 'password'); $link->select_db('database') or die ('Cannot connect to database'); } return $link; }and
    function body(){ $sql = db()->query("SELECT * FROM articles ORDER BY article_number DESC LIMIT 11, 15");1a. Notice that it's the OOP style. PHP 4's object-oriented support was... lacking. In PHP 5+ it's much better. You could stay procedural with the mysqli_* functions but try to learn OOP.1b. If you really don't want to do it then use db() in place of the $link in the regular function calls.
    2. The "or die()" pattern is very bad. Stop doing it and figure out something better.
    3. Putting database error messages in the die() is even worse.
     
    Likewise,

    while($row = mysqli_fetch_array($sql)){1c. $sql is also an object and you can do $sql->fetch_array() instead. 
    Also,

    stripslashes(extract($row));5. That doesn't work, least of all not the way you think it does.6. stripslashes() like that is not even needed in PHP 5+.
    7. extract()ing values is frowned upon for assorted reasons. Assign variables manually (yes, it's more code) or simply just reference the values in the $row array directly (easier).
  20. requinix's post in Can't Report on Mobile was marked as the answer   
    How about now?
     
    The reporting page isn't terribly pretty on mobile but at least it's accessible. And functional, I hope.
  21. requinix's post in is it possible to set permissions on a folder outside the root using yml was marked as the answer   
    Please remember to give context for people who don't know you're working with CodeDeploy.
     
    It doesn't look like their permissions system is particularly powerful - since "directory" only applies to descendant directories and "file" only applies to immediate files, you would need a bunch of sections listing out each individual directory whose files you wanted to change permissions on.
     
    Try deploying with a .tar/.tar.gz (and not a .zip) as those support specifying permissions inside the archive itself. No guarantee that CodeDeploy will keep the permissions on extraction, though.
     
    Otherwise I think I would give up and use a post-install bash script (or individual commands without the script) to apply permissions as you want. Probably with a combination of find+xargs+chown/chmod.
  22. requinix's post in Rearranging Our Forums was marked as the answer   
    Just updated the forums.
     
    If anyone has comments or suggestions about the changes, head over to the Feedback forum (which is now situated in the "General Discussion" category).
  23. requinix's post in summing using dynamic sql was marked as the answer   
    When it doubt, RTFM.

  24. requinix's post in Subtracting Time from Total Hours was marked as the answer   
    Apparently createFromDateString doesn't allow HH:MM format, even though it looks relative. It's because the relative format is shared with the other date/time parsing code and HH:MM is more of an absolute value than a relative one.
     
    So break the HH:MM into HH and MM parts and create the DateInterval manually. You do need to validate the break1 value first (make sure it is, in fact, HH:MM format) but the rest of the process we described works correctly.
  25. requinix's post in Script posting wrong date was marked as the answer   
    The $b++ at the top of the loop is still going to happen. And putting $cycle_day++ into that doesn't make any sense at all - yeah, it increments twice to make up for the missing $b day, but that doesn't justify it being there.
     
    The code is already plenty messy and long past the point of needing to be refactored, but fixing this should be close. If the first week works then $b=0..6 and $s=-1..5 works. So keep it in that range.
     
    Drop the $b
    Then deal with the $b++ problem. Resetting $b anywhere after it's used (which is just with the $s=$b-1 statement) won't be enough because it'll increment with the next loop. Drop the increment and

    $s = $b - 1; $b = ($b + 1) % 7;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.