Jump to content
Old threads will finally start getting archived ×

gizmola

Administrators
  • Posts

    6,020
  • Joined

  • Last visited

  • Days Won

    152

gizmola last won the day on February 25

gizmola had the most liked content!

7 Followers

About gizmola

Contact Methods

  • Website URL
    http://www.gizmola.com/

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

gizmola's Achievements

Prolific Member

Prolific Member (5/5)

355

Reputation

69

Community Answers

  1. When you connect to postgresql you specify a database. If you are connecting to the database you are trying to drop, you will be blocking your ability to drop it. Make sure you connect to the postgres database. If that is not the issue, and you are not connecting to mydb, you should be able to drop the database regardless of any other existing connections to it, using: drop database mydb with (force)
  2. The two ways are significantly different. The first way is the way you should do this. It uses the curl extension that is built into PHP. The 2nd way is creating a system shell and then executing a shell command that in your case happens to be the curl command. Many things could go wrong, and you will not have visibility into those issues. It is a less direct method, and doesn't have the same level of access to curl options and results.
  3. If this is for validation of emails, then a simple and effective solution would be to utilize filter_var. $email = 'bob@example.com'; function validEmail($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } if (!validEmail($email)) { echo "The email address provided is not valid"; }
  4. Someone told you? Who was that exactly? This behavior is caused by settings in the PHP.ini. See this page: https://www.php.net/manual/en/mail.configuration.php#ini.mail.add-x-header. You are able to disable these variables in the PHP.in configuration. The mail() function drops mail off for the system Mail Transfer Agent. In many cases, hosting companies utilize those variables to insure that outbound mail is authorized, and this may end up stopping mail delivery. You should contact your hosting provider to inquire about disabling the settings.
  5. Not much we can do to help you with this little information. It sounds like you have a hosting company, and it sounds like the hosting company tools have limits or don't work very well. You should seek support from them.
  6. Debugging a web application is a non-trivial exercise in most situations. VSCode is not a web server, so if you're developing a web application, you are not going to have much luck without a good understanding of both xdebug and the vscode debugging extension. You will need both. To try and simplify it, xdebug is a php extension that needs to run where your PHP code is running. Again as a web application, that is likely to be either within a local webserver + php environment, or possibly within a docker container (that has the PHP server), or even on a "remote" server. The point is, that there are many different ways to run "serverside" PHP, and for that reason, there isn't a simple answer. What I can say, is that xdebug is actually a multi function extension that provides a step debugger a profiler (for timing) a code coverage analyzer a function tracer So there are a myriad of different switches and options it allows for. Purely from the step debugging point of view you have to understand a couple of things: XDebug implements a debugging protocol called DBGP Any editor that can talk DBGP will work with xdebug. The actual "debugging" you think of, is really more of a trick, whereby xdebug accepts information about source files and line numbers for things like breakpoints, and the editor can then use this to synchronize your view of things, provide information about variables and functions, the stack etc, but in reality it's sort of an illusion, in that the code is not ever running within VSCode. So you have to realize that XDebug is in charge of debugging. It does this by connecting to VSCode and at that point, will allow for communication. So when you saw the message about a connection, it was because the editor can't do anything since there is no configuration setup to allow the INCOMING connection from the server where xdebug is installed back to VSCode. The problem with any how-to for setting up xdebug with vscode, is that it entirely depends on where the server with xcode installed is running. With that said, at this point, most people using vscode are using this extension to facilitate the configuration you need. Another thing to understand, is that with a web application, you typically need a way to initialize the debugging conversation, and start the debugging session from the web application. In most cases, people will use a cookie addon that sets a special cookie in your browser, which the server will see. There have been a number of these browser extensions over the years, but luckily at this point there is one that Jetbrains has backed here: https://github.com/JetBrains/xdebug-extension There are versions for different browsers. You will use this browser extension to setup the cookie needed to tell xdebug to start a debugging session in your VSCode. Once started xdebug will try and connect back to your IDE on the port you configure. So this means that port based networking is involved. By default (assuming step debugging is enabled) that port is 9003. See xdebug.client_port in the manual. So your IDE needs to be configured to open up port 9003, which is what the vscode extension helps you do. I recommend you try and read through this: https://xdebug.org/docs/step_debug There are many links in there to information about particular environments and videos to help you try and get it working.
  7. A singleton is an OOP design pattern. The design of a singleton is such that there will only be ONE (a single) object of the singleton class. Objects of a singleton class are made using a static method. The wordpress wpdb class source code is here. It does NOT implement a singleton pattern. The $wpdb global object however, is intended to be used throughout Wordpress and by any plugins. So you CAN create new objects of class wpdb, so long as you understand what that requires. It is not clear from your question why you need a 2nd database connection. As for your shared host, you should investigate the # of database connections they have configured. In phpMyAdmin you can use a query like this to see how many connections your hosting company has configured. SHOW VARIABLES LIKE 'max_connections'; The default value is 151. I have heard of certain shared hosting companies setting this value arbitrarily low. If you want to report back to us what you find, we can weigh in on the reasonableness of the limit. In many cases you can open a ticket with the hosting company to have them increase the mysql parameter that controls this limit. As for closing a database connection, no you don't need to worry about closing it. PHP has page/script scope, so as soon as the page is complete, PHP already disposes of all variables and releases any resources. If you have a small amount of code that makes a few queries and you are absolutely sure that you are done with the connection you made, then it doesn't hurt to do something like this: $my_wpdb = new wpdb(....); // make queries etc. $my_wpdb->close(); unset($my_wpdb); But it really is a micro-optimization that is not worth doing.
  8. I feel like I have advised this before, but change all your include_once() calls to require_once(). Is the code you provided above the code for the DataInput.php script? As @mac_gyver stated: you have assumptions as to what loads or doesn't, that we have no way of validating.
  9. I would remove that from the .htaccess file. That is not the type of setting you should need. GoDaddy should already be configured to support php scripts, purely by the extension of .php.
  10. I guess the important thing is that you understand what GROUP BY does. It reduces the results, so that you get one row PER group. I hope you understand my intentionally simple but straightforward example and what it means for your queries. Going back to what mac linked you, the reason your old code doesn't work is because, the MySQL server "default" behavior changed. The error you provided tells you this: So this is the setting that is now on where before it was off. The MySQL manual explains that you can turn this setting off on a per session basis, but also includes this warning: So it's telling you, that when you reduce the result set with group by, any fields that are not part of the group by (or part of a summary function) are "nondeterministic", which means, "we include whatever random column value out of all the available ones that were in the original result set before it was grouped." In other words, that data could change from query to query for no apparent reason. So you have a couple of options here. One is to rewrite the query so that you aren't just using SELECT *. You use SELECT * and then you specify a few columns again for reasons that aren't clear to me. In general, it is best to only provide the fields you need in the select list. Your query does a join to a table with a 1-M relationship (a_players_reviews) for reasons unknown to me. It is an inner join, which means that unless there is at least 1 a_players_reviews rows for an event, there will not be a row in the result set (group by or not) for that event. I don't know if that is by design, or not, but it isn't really clear why you'd design the query to make that join only to group out the results, while also knowing that without a review, the event won't even appear in the list.
  11. Yes, just unset any specific variables in $_SESSION. Generically you can use: foreach (array_keys($_SESSION) as $key) { unset($_SESSION[$key]); } This is the recommended way that doesn't cause the entire session mechanism to cease functioning. The user will still have a session, but it will be empty.
  12. That is how PHP works. An "unchecked" checkbox is not sent in the POST data. Your serverside validation should check for this, and handle it accordingly.
  13. As maxxd illustrated, the important thing to understand is that every class has a constructor. Parameters that are essential to the creation of the object need to be defined in the class constructor. If you don't provide a class constructor, a default one is called. This is typical across Oop languages. So you want to think about what data the class will need to fulfill it's goals, and require those as parameters in the constructor. You don't call the constructor directly, it is called when you create an object using new: $someVariable = 88; $someArray = ['monday', 'wednesday']; $dtObj = new DateTime(); $myObj = new MyClass('Some Data', $someVariable, $someArray, $dtObj); $report = $myObj->getReport(); As an example here, you would have to assume that the MyClass constructor MyClass::__construct(....) would accept at least 4 parameters, based on this example, and would have a need and reason for these parameters. Frequently the only thing the constructor is going to do is assign those parameters to class variables defined in the class. Maxxd's example code illustrates this perfectly. The important thing to consider when designing the class methods is what the "interface" is for talking to it by calling methods. With PHP you can formalize this idea with a separate interface definition, but I'm not going to go into why you would use interfaces or not. All I want to clarify is that you can think of the interface to your object as the list of PUBLIC methods you defined in the class. In your code, anytime you will want to directly call a method, that method needs to be defined as public. Certain magic methods like the __construct() method are required to be public. But you can also have methods that are only used within class code. Those methods should be either private or protected. In most cases you will want to start by making those internal methods private. You also want your class variables to be private (again see Maxxd's example class!, notice that he defined the one class variable $details to be private. This means that a user can not do this: $details = ['Add Button', 'New List Screen']; $fr = new FeatureRequests($details); echo $fr->details[0]; Because the class $details variable was defined as private, you can't directly access it. This is a typical design choice, that facilitates the OOP principle of "information hiding" where the form of the internal data structure(s) of the class are hidden from code using that object. A user should not know nor depend on what the form of the details class variable is. The only thing that a user of a class should be interested in is the public methods the class provides.
  14. It's been a long time since I've written any Java code, so it took me a while just to get things setup to investigate this, but here you go: import java.util.Arrays; public class Main { public static void main(String args[]) { int[][] wh2d = { {0, 34}, {1, 28}, {2, 20}, {3, 31}, {4, 32}, {5, 28}, {6, 37}, {7, 41} }; System.out.println("Before sort----"); for (int i = 0; i < wh2d.length; i++) { System.out.println(Arrays.toString(wh2d[i])); } System.out.println("-------\n\n"); Arrays.sort(wh2d, (a, b) -> { System.out.println("----Lambda------"); System.out.println("a[0]:" + a[0]); System.out.println("a[1]:" + a[1]); System.out.println("b[0]:" + b[0]); System.out.println("b[1]:" + b[1]); if (b[1] == a[1]) { System.out.println("eq-lval:" + (b[0] - a[0])); return a[0] - b[0]; } System.out.println("ne-lval:" + (b[1] - a[1])); return a[1] - b[1]; }); System.out.println("\n\nAfter sort----"); for (int i = 0; i < wh2d.length; i++) { System.out.println(Arrays.toString(wh2d[i])); } } } Results: Command Line Arguments   Before sort---- [0, 34] [1, 28] [2, 20] [3, 31] [4, 32] [5, 28] [6, 37] [7, 41] ------- ----Lambda------ a[0]:1 a[1]:28 b[0]:0 b[1]:34 ne-lval:6 ----Lambda------ a[0]:2 a[1]:20 b[0]:1 b[1]:28 ne-lval:8 ----Lambda------ a[0]:3 a[1]:31 b[0]:2 b[1]:20 ne-lval:-11 ----Lambda------ a[0]:3 a[1]:31 b[0]:1 b[1]:28 ne-lval:-3 ----Lambda------ a[0]:3 a[1]:31 b[0]:0 b[1]:34 ne-lval:3 ----Lambda------ a[0]:4 a[1]:32 b[0]:3 b[1]:31 ne-lval:-1 ----Lambda------ a[0]:4 a[1]:32 b[0]:0 b[1]:34 ne-lval:2 ----Lambda------ a[0]:5 a[1]:28 b[0]:3 b[1]:31 ne-lval:3 ----Lambda------ a[0]:5 a[1]:28 b[0]:1 b[1]:28 eq-lval:-4 ----Lambda------ a[0]:6 a[1]:37 b[0]:3 b[1]:31 ne-lval:-6 ----Lambda------ a[0]:6 a[1]:37 b[0]:0 b[1]:34 ne-lval:-3 ----Lambda------ a[0]:7 a[1]:41 b[0]:3 b[1]:31 ne-lval:-10 ----Lambda------ a[0]:7 a[1]:41 b[0]:0 b[1]:34 ne-lval:-7 ----Lambda------ a[0]:7 a[1]:41 b[0]:6 b[1]:37 ne-lval:-4 After sort---- [2, 20] [1, 28] [5, 28] [3, 31] [4, 32] [0, 34] [6, 37] [7, 41] I suspect that the confusion in this code might come from the declaration of: int[][] wh2d = { {0, 34} }; //vs int[][] wh2d = { {0, 34, 90, 75} }; These are both valid definitions, because the 2nd dimension is an array of integers. I suspect the confusion might come from thinking that the first dimension of the array will be the element inside the pairs of numbers provided for the 2nd array. That would be an incorrect assumption. The first array dimension is simply numerically indexed from 0..n items. Given that the 2nd dimension contains arrays with 2 items, and in each case you want to compare the 2nd element, you need to use a custom "Comparator". I'm reminded at hard it is to do simple things in Java and C++, when compared to interpreted languages like Python, Javascript and PHP. The important thing to understand is that the Lambda is a stand in for an integer Comparator, which requires the return of an integer value (+, 0, -). Based on that return, the elements in the first dimension will be swapped (or not). I put in a lot of debugging output in the Lambda, so you can hopefully follow what is happening in the lambda.
  15. Barry, the op posted some java code unfortunately. OP Got the right sub forum, but neglected to include that information. int[][] wh2d = { {0, 34}, {1, 28}, {2, 20}, {3, 31}, {4, 32}, {5, 28}, {6, 37}, {7, 41} };
×
×
  • 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.