Posts by rray • 66,288 points
1,220 posts
-
0
votes2
answers92
views -
11
votes5
answers1643
viewsA: Difference between private and final methods
The keyword final means that the method defined with it cannot be overwritten in a subclass. Private methods are only accessible within the defined class, so it is not possible to access/overwrite a…
-
5
votes2
answers209
viewsA: PHP - Convert ISO8601 standard (used by Youtube) to seconds
PT1M31S is a time format, meaning time period of 1 minute and 31 seconds, so treat this string as a Datetime. Create a new date and add this range through the method add(), which receives as an…
-
3
votes2
answers1621
viewsA: mPDF - Error generating PDF | Message: preg_replace():
As quoted in the comments, the modifier e(Eval) of the functions preg_* was discontinued in php5.5 and removed in 7.0, instead it should use function preg_replace_callback(). To fix the problem,…
-
0
votes3
answers4717
viewsA: I can’t connect with postgresql in php
Will not connect this way, it is necessary to inform the full dsn, with host, user and password beyond the database. $connect = pg_connect("host=localhost dbname=teste user=usario password=senha");…
-
2
votes2
answers500
viewsA: How to use Regular Expression correctly
Its validation means, the input value of CPF should only receive numbers (or only one) that is expressed by [0-9] the square bracket means it’s a list, the 0-9 is the range of caractars allowed. The…
-
2
votes1
answer2421
views -
1
votes1
answer198
viewsA: XAMPP 5.6.16, apache error with globlas on
This feature was removed from php in version 5.4 according to the manual http://php.net/manual/en/security.globals.php. The way is to use a little regex to replace certain code snippets.…
-
6
votes3
answers11214
viewsA: What is Code Smell?
code Smell/bad Smell, is the term used to show that something in the code does not make sense (lack of cohesion), if this problem is not treated will spread, the cost and effort to correct it will…
terminologyanswered rray 66,288 -
1
votes5
answers11978
viewsA: How to get the current file name
The combination explode() & end() can get the same result(take the current file name); The explode() transforms the string returned by __FILE__ in an array, the delimite is the directory bar…
-
1
votes1
answer484
viewsA: How to compare array to string?
Make sure the string inside $buscaMov be the comparison table, set a pattern ex, use minuscules and also remove the spaces at the beginning and end of the string with the trim() Change: to: if…
-
2
votes1
answer491
viewsA: Rule in model to format date
To change the date format of an object DateTime which cake probably uses, use the method format(). Change: public function data($check) { $dataDespesa=explode("/", $check['data_despesa']);…
-
4
votes2
answers1768
viewsA: What is and what is php.ini for?
PHP.ini is the file with PHP settings ranging from extensions, directives, configuration of directories such as log, default locale. To define specific configurations of a system or an environment…
-
4
votes8
answers1094
viewsA: Is it recommended to use constants for configuring a PHP project?
Constants are used as pieces of information reusable from formal (usually) global and immutable, that is, it does not change. In case you create a password constant for your database it is highly…
-
1
votes3
answers4269
viewsA: Detect browser language and redirect
You can get this setting using the class Locale library lntl, which is available from php5.3. <?php echo 'Disponiveis: '. $_SERVER['HTTP_ACCEPT_LANGUAGE'] .'<br>'; $lang =…
-
5
votes3
answers699
viewsA: Search word with file_get_contents
Can use preg_match_all() to make this search, the results are stored in the third argument($matches). <?php $content = file_get_contents( 'https://www.hostgator.com.br' ); $regex = '/equipe/';…
-
2
votes2
answers998
viewsA: phpmailler error while sending email
To set your function, first hit the array of emails, the code below will store only the first email from the database. $query = "SELECT * FROM newsletter"; $result = $mysqli->query($query); $row…
-
16
votes3
answers481
viewsQ: Difference between location and internationalization
Sometimes the software developed should be available in more than one language and go through a 'process' of internationalization or localization. What are the differences between localization…
-
4
votes5
answers9719
viewsA: Copy data from one database to another postgress
You can do this with postgres via an extension called dblink the installation is in the postgres contrib or Shared extention folder, it is a script just run it and will be created 40 and few…
postgresqlanswered rray 66,288 -
0
votes2
answers1206
viewsA: How to reference foreign keys in registration forms?
Most complete version: Your form must be mounted with at least this information, a text box for the name, after typed the name is made an ajax request for PHP to fetch the matricula based on the…
-
5
votes3
answers988
viewsA: Is it possible to include more than one.php file in the path of a Require?
Let’s say all your includes files are in a folder the part called includes and your index at the project root, you can create a function that does all these requires/includes. Use glob() to list all…
-
12
votes3
answers228
viewsA: I need an explanation about what a code I don’t understand does
It is a ternary that checks whether $i is an odd number using the two module, if positive returns a piece of html that is the definition of a class(css) otherwise an empty string is returned. The…
-
3
votes1
answer808
viewsA: I can’t change records from a database table
First, don’t use the mysql_* functions, they’ve already been removed from php7, arrobas are more disturbing than they help they hide the errors, an error message is better than 'nothing happens''.…
-
2
votes2
answers914
viewsA: Artisan Laravel not installed
To use Artisan commands you need to be in the project folder in the terminal.
-
2
votes1
answer314
viewsA: How to loop within a query?
If removing one of the ties will achieve the expected result: $tel_query = "SELECT * FROM tels"; $variavel_exe = mysql_query($tel_query) or die(mysql_error()); $indTelefone=0; $indCelular=0;…
-
5
votes2
answers117
viewsA: Doubt in the security of PHP PDO
In terms of security there is no difference. One of the differences is that bindParam() in addition to offering parameter typing(PDO::PARAM_STR, PDO::PARAM_INT etc) has other obscure features for…
-
2
votes3
answers43
viewsA: Name a csv file
Use the function glob() to list all csv files, do this get the date contained in the name, with the explode() the index containing ta is 1 and the time the 2, swap out the . for :, add this new…
-
1
votes3
answers223
views -
5
votes2
answers71
viewsA: Failure to compare dates before saving to the bank
You can check if the date is retroactive with the class Datetime, through property invert, on returning 1 means that the result of the calculation is negative if it is 0 is positive, use diff() to…
-
1
votes1
answer1150
viewsA: Column not found: 1054
The field id does not appear to exist in the model/table, what is defined in it is id_postagem The error says: Unknown column 'postagens.id' in 'Where clause' where `postagens`.`id` Model: protected…
-
24
votes8
answers5012
viewsA: Printing a String until a space is found
You can use the function strstr() because it retouches only the first part of that string. By default the returned value is to the right of the limiter. To change this is to take the value on the…
-
5
votes2
answers939
viewsA: Query returns empty using PHP with PDO and MS Sqlserver
Pass the jokers on bindValue(), do not leave them in the query otherwise they will be escaped and then your query will fail. It seems that the SQL Server driver has a detail, does not allow using…
-
5
votes4
answers201
viewsA: Simplify IF instructions in PHP
Another way to make these comparisons is to transform the variables into an array and create another array as a template, so compare if the data sent by the user is equal to the information of some…
-
2
votes1
answer159
viewsA: What is the best option to escape a string before inserting it into the database. addslashes() or mysql_real_scape_string()?
mysql_real_scape_string() should be discarded because it is obsolete, removed from php7 and requires a mysql connection_*. Let the PDO handle escaping characters using Prepared statements.…
-
3
votes3
answers4534
viewsA: Convert json object in php
Private members are not converted by json_encode() your class in this case can implement a method that gets all the 'variables' of the class and returns a json. Example that reproduces the error:…
-
6
votes2
answers393
viewsA: Firefox claims code after Return
The syntax error already breaks the code and this is a problem. This error means "Look, here’s dead code (will never run) after the return. Remove him before someone thinks he’s good for something".…
-
5
votes2
answers1059
viewsA: How to create a csv from a database and data query
Csv is a file with values separated by commas, can create a matching implode() to transform the array($escrever) in a string bounded by commas and use file_put_contents() to write the file. Another…
-
2
votes2
answers3436
viewsA: How to mount a JSON return?
Format the date by the bank with date_format() so you don’t have to do it by php. Create a new array, format the currency value and 'stack' the items at the end of the function return the a…
-
3
votes2
answers70
viewsA: How to insert the connection inside the functions without repeating the instructions?
May pass $pdo as an argument for functions or to create a class to share the connection between methods. Do not inject global or external variables into a function because they can break the…
-
1
votes1
answer43
views -
2
votes2
answers329
viewsA: select Pdo com oo
To get the number of rows returned I suggest you create a property $rowCount it will have changed value whenever a select is run. What changes from a select with Where to a without is whether some…
-
1
votes4
answers1466
viewsA: Camelcase conversion function
Another way to perform this task is to use a regex where default matches the dash followed by the next character which is expressed as: -(.) to make the subustituition use strtoupper() group(that…
-
2
votes1
answer601
viewsA: Data insertion problem in mysql table
Do not use the functions mysql_* are obsolete and have been removed from php7, do not use @ it hides errors which makes it difficult to detect the problem. If you’re a legacy project all right,…
-
13
votes1
answer5591
viewsA: How to make SQL query that ignores uppercase, lowercase and accents?
To make an independent search of upper or lower case, change the LIKE for ILIKE. The operator ILIKE is specific to Postgresql and its behavior is similar to LIKE. The only difference is he’s…
-
1
votes2
answers332
viewsA: Read string json in php
Utilize json_decode() to transform the string into an array informing the second argument as true, then do the foreach. <?php $str =…
-
2
votes2
answers512
views -
2
votes2
answers318
viewsA: How to echo a variable of this function?
Return $path at the end of its function. Local variables (those declared within the function) are not accessible in other parts of the code. You can define an associative array with the directories,…
-
3
votes3
answers8265
viewsA: Batch rename files using Windows Power Shell
Can solve the problem by combining cmdlets Get-Childitem to list the directory files and Rename-Item to rename them $raiz = "c:\ps" $arquivos = Get-ChildItem $raiz -Filter "*.txt" | Where-Object…
powershellanswered rray 66,288 -
22
votes5
answers5756
viewsA: What is Design Pattern?
Design Pattern is the term used to describe a solution to a problem that occurs frequently and also a way to summarize the idea of a code implementation, rather than describing the code you speak…
-
1
votes3
answers756
viewsA: Send parameters via GET
Your query is returning a syntax error when it is $ordem has some value something like: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the…