Posts by gmsantos • 17,221 points
395 posts
-
3
votes2
answers395
viewsA: How to verify if a constant exists in the class or in a namespace?
You will use the function defined(). In both cases you need to inform the namespace complete: <?php namespace StackOverflow { const LANG = 'pt-br'; class StackOverflow { const MY_CONSTANT =…
-
2
votes5
answers580
viewsA: Doubt in SQL query "between" or "in"
The BETWEEN expects the first parameter to be smaller than the second, which causes your problem. Use the IN also does not solve your problem because it does not work with intervals, but rather with…
-
1
votes1
answer937
viewsA: Deleting local image of Laravel product
When deleting the product, your method destroy also need to delete the created file. You can do this directly in the method: public function destroy($id) { $disk = Storage::disk('local');…
-
3
votes1
answer2396
viewsA: Connect Mysql Workbench to Hostinger Server
If you are using the free version see this issue in the knowledge base theirs. How to access Mysql remotely: Unfortunately, we do not support external Mysql connections on the plane for safety and…
-
2
votes3
answers4457
viewsA: Calling Java application via PHP
One way to consume a Java application from PHP is by using Zend Java Bridge. It allows you to consume your classes created in Java from your PHP script. Follow the stream that runs to run this Java…
-
3
votes1
answer547
viewsA: Instantiate class outside namespace
For being inside the namespace App by instantiating the class Util PHP is looking for the class App\Util, which does not exist. It is necessary to specify that you actually want to use the class…
-
0
votes2
answers238
viewsA: Error installing Laravel: Package not available in stable version
I couldn’t reproduce your problem here. The command worked perfectly. Try the following steps: Update your Composer composer self-update Install the package again, but with a more relaxed version…
-
0
votes1
answer67
viewsA: Enable extensions in Google App Engine
Google App Engine does not support this extension yet. What you can do is open a Issue and hope to implement. Maybe include a package to simulate the functions fileinfo() can solve your problem.…
-
4
votes1
answer402
viewsA: Variable of type Object within a class
PHP is a language with dynamic typing, that is, unlike Java we do not define the type of the variable. To guarantee the type of our property we use the hinting type together with the encapsulation.…
-
4
votes1
answer458
viewsA: Inner Join table on 1 = 1 can be considered a gambiarra?
Yes, it is a trick. The correct thing in this case would be to apply a CROSS JOIN SELECT (SELECT count(ia.idaluno) FROM inscricaoaluno ia INNER JOIN alunos a ON a.idaluno = ia.idaluno WHERE…
-
2
votes1
answer82
viewsA: Is it possible to know at what point the script reaches the memory peak?
This is possible through a profiler. Some options are the Xdebug, xhprof and the Blackfire io.. You would need to install on your server the respective extension and analyze the profiler in search…
-
1
votes3
answers471
viewsA: How to make webservice run without user interaction?
To do what you want PHP will need a "little help" from outside: from your server’s OS. Conceptually you will use a cronjob to run your service from time to time via command line: > * * * * * php…
-
1
votes4
answers504
viewsA: Filter numbers not yet registered via SQL
If you are using one SEQUENCE it is possible to predict what the next codigo to be inserted. CREATE SEQUENCE codigoUsuario; To select the code: SELECT nextval('codigoUsuario'); When creating your…
-
5
votes3
answers17275
viewsA: Error #1062 - Duplicate entry '1' for key 'PRIMARY'
As reported by the error message, the field sub_id is not unique and repeats itself. It seems to me that your table has a composite key between area_id and sub_id. Try to define both columns as…
-
3
votes2
answers792
viewsA: Limit number of Group By occurrences
By default Mysql does not do this, but we can improvise. Assuming your original query is this SELECT id, data, SUM(visualizacoes) FROM tabela GROUP BY id, data ORDER BY id, data DESC; Place your…
-
6
votes2
answers1099
viewsA: How to remove formatting from the GETDATE() command
For SQL Server as of 2012, use FORMAT() SELECT FORMAT( GETDATE(), 'yyyyMMddHHmmssfff' ); See the date format character patterns here.…
-
6
votes1
answer996
viewsA: PHP hashtag system
As mentioned in the comments, the ideal is to separate the tag from the message. I would go a little further and make a table only for tags, taking into account that a message may have multiple or…
-
3
votes1
answer592
viewsA: Laravel validation
You cannot directly use the Request Validation of Laravel 5, but you can use the Validator with any array. First read the XML contents. <?php public function validate(){ $xml = '<book>…
-
3
votes1
answer178
viewsA: Pure XML in PHP
Note that when using simplexml_load_string() you are interpreting the reply XML. If you want pure XML just use the previous variable: $client = new…
-
4
votes2
answers1586
viewsA: Percentage PHP and Mysql
The formula is correct yes. I particularly like multiplication after division: ( totalCategoria / totalProdutos ) * 100 It is possible to do what you want with just a summary query to the bank:…
-
1
votes1
answer267
viewsA: Whole data not saved in table as the Eloquent of Laravel 5
When using the method create of a model Eloquent the Laravel assigns the properties via mass assignment By default the model User already comes with this pre-filled property: class User extends…
-
4
votes1
answer3176
viewsA: Return query on same page
Change the condition of your if for something like this: <html> <form name="registar" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden"…
-
4
votes2
answers1784
viewsA: Take the line break in a file and put the content in a variable
You can use the function explode() for that reason: $nomes = explode("\n", $arquivo); If you only want to view the data, you can use the nl2br() or iterate the results: echo nl2br($arquivo);…
-
2
votes2
answers402
viewsA: About Mysqli functions
If you’re inheriting from the class mysqli all available methods will be in your new class. No need to create new methods for this: <?php class MeuBanco extends mysqli{ // ... } $db = new…
-
1
votes2
answers70
views -
2
votes2
answers2501
viewsA: How to echo a php file?
You can do the following: $conteudo = file_get_contents($_FILES['arquivo']['tmp_name']); Explanation: When giving a var_dump() of the variable $_FILES['arquivo'] we may notice an array with some…
-
0
votes2
answers765
viewsA: How to configure the Doctrine terminal together with a Codeigniter project?
I just answered a question about how integrate Doctrine with Codeigniter. I created the file cli-config.php copying some of the index.php and referencing the EntityManager raised in the…
-
5
votes1
answer2008
viewsA: Install Codeigniter 3 with Doctrine and Composer
TL;DR I climbed into the Github an example project integrating Codeigniter 3 with Doctrine, accompanied by an example. The error is in the way you use the self-loading. In the archive doctrine.php…
-
2
votes2
answers401
viewsA: Erro Foreign Key
This error happens because the table that will be referenced in Foreign Key must exist at the time of key creation. In this case you must enter the keys in a separate query: CREATE TABLE funcionario…
-
1
votes2
answers56
viewsA: Add class to Regex result in preg_replace
Use Regex with HTML it’s not a good idea. Instead you can use the DOM: <?php $dom = new DomDocument; $dom->loadHTML("<li><p>a) longo texto</p></li>"); $lis =…
-
11
votes2
answers538
viewsA: Why omit the PHP closing tag?
A good reason is to prevent unwanted whitespace from appearing in our files, which may possibly cause the Error - Cannot Modify header information. As you can see in this question, there are several…
-
0
votes2
answers1325
viewsA: Browse query records with PHP PDO
In PHP you can browse an array similar to the following functions: current() - Returns the current element in an array each() - Returns the key pair/current value of an array and advances its cursor…
-
1
votes3
answers1500
viewsA: Copy bank record
You are probably duplicating some primary key of your table or some column with Constraint UNIQUE. You can specify the fields individually you want to copy (as per Toby’s reply) or create a new…
-
2
votes1
answer781
viewsA: Class for handling database connections
It would change in its class the following points: Remove the abstract class: The purpose of an abstract class is to be the basis of an inherited class. In your case it is being used to prevent the…
-
0
votes3
answers86
viewsA: Using variables in the Model
It is not clear to me what the purpose is to store the return of this function back in your Model. But you can do this by creating a property in the class of your Model to store the data you will…
-
7
votes2
answers104
viewsA: Error executing cascade class methods
To execute the code this way (Method Chaining) it is necessary that your class Customer implement a standard called Fluent Interfaceen. To be able to do this in PHP it is necessary that the methods…
-
4
votes2
answers637
viewsA: How to decrypt a php code
The file is not encrypted, per se. Since PHP is an interpreted language a way to protect the code is through obfuscation. Obfuscation consists of "messing up" the code so that it is not…
-
1
votes3
answers271
viewsA: How to optimize SQL queries containing SELECT-related DELETE?
The following query will give you the same result (assuming the name of the fields in your table are consistent): DELETE FROM items_rooms where base_item IN (SELECT base_item FROM catalog_items…
-
3
votes2
answers177
viewsA: How to create an algorithm that automatically tracks certain pages of a website?
I don’t think tracking the page for inappropriate comments is the best option. What you can implement is an algorithm that creates an approval queue for comments, requiring all comments to be…
-
2
votes1
answer180
viewsA: Warning when using preg_match()
When using regular expressions in PHP like preg_match() we must insert an extra delimiter into our Pattern. Your error is not to use any delimiter: if (!preg_match('/' . $SUBMENU .':/', $sm))…
-
2
votes3
answers154
viewsA: Optimization of PHP functions for database querys
To do this kind of functionality at hand for me is to reinvent the wheel. I like to use the Doctrine DBAL to work with database abstraction. In it I write the code at once and it will run…
-
0
votes2
answers238
viewsA: Form construction
It is worth remembering that the illuminate/html continues to exist as a component of the Laravel and works perfectly with the Laravel 5. Run enter dependency via Poser: composer require…
-
0
votes2
answers4659
viewsA: Laravel update via Composer
The problem is time for Composer to download updates. Laravel includes in the Composer file some internal commands for Cache cleaning, Autoload optimization, etc: "scripts": { "post-install-cmd": […
-
1
votes1
answer477
viewsA: Using Codeigniter configuration file sessions
For your case, I believe you have to create an extra setting while running the program. From agreement with the documentation you can change the DB configuration as follows: <?php…
-
1
votes3
answers436
viewsA: Why is array_shift considered a slow function?
Creating an alterative "manual" is really the best way to solve this problem? The function array_shift has a running time of 2n, that is, the larger the array, longer it will take. This is only a…
-
5
votes2
answers437
viewsA: Is declaring a class named after a reserved word a good idea?
In reality you cannot use the reserved words (so-called language builders) anywhere. The functions you were able to create and worked (Int, String, Object) are not reserved words, according to the…
-
1
votes1
answer289
viewsA: Organization of PHP files
One way to work with the paths is to define before your require a constant with the path to the root directory of your project. From there you don’t have to worry where your script is. <?php…
-
2
votes3
answers2967
viewsA: How to remove the last character from the last value of an array
Using the functions substr and functions end and key <?php end($items); $key = key($items); $items[$key] = substr($items[$key], 0, -1); In this case it works with associative arrays (no numerical…
-
1
votes3
answers273
viewsA: What can change with the variadic Function implementation?
In my view the variadic function will replace call_user_func_array and func_get_args. They would stay there for a few releases to maintain compatibility with code that needs to work in earlier…
-
5
votes1
answer1981
viewsA: Problems configuring Composer with XAMPP in Windows environment
You are confusing things. Composer is a project-level package manager. You will not create a file composer.json in your PHP folder, but in the folder of each project: Project directory before the…