Posts by rbz • 9,949 points
356 posts
-
1
votes2
answers927
viewsA: Return reading in JSON
Rule: { } = JSONObject [ ] = JSONArray So: String json = "{\"carro\":[{\"celular\":\"123456\",\"_id\":\"1\"}]}"; try { JSONObject jo = new JSONObject(json); String carro = jo.getString("carro");…
-
0
votes2
answers125
viewsQ: Array search, with multiple key relations x value
Example scenario I got the following Array: array ( 0 => array ( 'A' => 'X', 'B' => 'Y', 'C' => 1, ), 1 => array ( 'A' => 'X', 'B' => 'Y', 'C' => 2, ), 2 => array ( 'A'…
-
2
votes2
answers96
viewsQ: Why does Return "terminate" the script even if in a condition?
Example scenario Example 1 $var = 'A'; function testar($v) { echo 'Início'; if ($v == 'A') { echo ' : true'; return true; } else { echo ' : false'; return false; } echo ' : Fim'; } testar($var);…
-
1
votes2
answers104
viewsQ: Use/change property of an extended class and print by instance
Example scenario Root folder Classea.php Classeb.php index php. Filing cabinet: classeA.php class ClasseA { public $retorno = null; public $error = "Erro desconhecido"; function __construct { $this…
-
0
votes2
answers61
viewsA: Address validations / class / method
I was able to solve using the file_exists, class_exists and method_exists. PS: As cited by Maniero, being dynamic can bring security holes. In my case treated before reaching that method, but…
-
2
votes2
answers61
viewsQ: Address validations / class / method
Setting I use a method to dynamically instantiate classes and methods. Properties received: modulo = name of briefcase with the files .class.php ferramenta = name of filing cabinet .class.php acao =…
-
0
votes2
answers91
views -
4
votes2
answers193
viewsA: Jsonobject with multiple values without using Array
I did, in response: // Criando objeto JSON raiz JSONObject JOraiz = new JSONObject(); // Criando objeto JSON auth JSONObject JOauth = new JSONObject(); // Adicionando propriedades e valores ao…
-
4
votes2
answers193
viewsQ: Jsonobject with multiple values without using Array
Goal Create a JSON with the following structure: { "auth": { "user": "rbz", "token": "abc123" } } Setting Creating the root structure: JSONObject JOraiz = new JSONObject(); Creating the values user…
-
2
votes1
answer231
viewsQ: Use ON UPDATE CURRENT_TIMESTAMP when changing specific field
Example scenario Table: usuarios Campos: id, nome, sobrenome, senha, timestamp_alteracao Question The field timestamp_alteração, should only be updated when the field senha is amended. Doubt There…
-
2
votes1
answer113
viewsQ: Sum seconds, minutes and/or hours in field date time
I have a field with date and time in Excel (column F) and I would like to sum seconds, minutes and/or hours, but the form used, as in the image example below, sums the value in days (column G): How…
-
4
votes1
answer85
viewsQ: Does using CTE (Common Table Expression) create a type of "cache" in the database?
I have an appointment with several JOIN and queries, and when executed, it takes about 7 seconds to return. Getting the same result, using CTE’s, the query takes around 8 seconds of the first…
-
0
votes3
answers1978
viewsA: Merge 2 Oracle SELECTS and as a result 2 columns with different values
Edit #1 SELECT data, VLRVENDAS FROM web.demonstrativo_processados WHERE nroempresa = 1 AND data between to_date('2017/01/01' , 'yyyy/mm/dd') AND to_date('2018/12/31' , 'yyyy/mm/dd') With UNION:…
-
2
votes1
answer463
viewsA: Wrong sequence MYSQL line numbering
Try to get subquery: SET @n = 0; SELECT @n := @n+1 AS linha, tab.* FROM (SELECT pergunta, resposta FROM perguntas p INNER JOIN respostas r ON r.pergunta_id=p.id) as tab; Functioning in the DB Fiddle…
-
1
votes1
answer152
viewsA: SQL rule to filter only one month in TIMESTAMP field
There are many ways to do it. Some examples: Using BETWEEN to pull a break: SELECT * FROM tabela WHERE timestamp BETWEEN '01/03/2018 00:00:00' AND '31/03/2018 23:59:59' Using MONTH to filter only…
-
3
votes3
answers58
viewsQ: Field referring to the MAX
I have the following table/fields: Table: PLANS ID (PK) VEICULO (IS REPEATED) DATAINCLUSAO REVISAO (UNIQUE) I need to bring the number of REVISAO of each VEICULO of the latter DATAINCLUSAO. So I can…
-
3
votes2
answers86
viewsQ: Does PDO use DBMS syntax or do they all work?
When considering the use of PDO, one of the main usability is the scope of several databases. Example scenario Different ways to filter 5 records, which vary by database: SELECT TOP 5 campo FROM…
-
1
votes2
answers919
viewsA: Exchanging column values in Mysql
Some possible possibilities One way would be by temporary table: TEMPORARY TABLE. How to create a temporary table: CREATE TEMPORARY TABLE temp_table SELECT X, Y FROM suatabela Applying the update:…
-
0
votes1
answer68
viewsQ: LDAP authentication, returns true if the password is null
LDAP authentication seems to have a bug. Script # Dados do servidor $server = '192.168.0.1'; $domain = '@meudominio.dom'; $port = 389; # Dados para acesso $auth_user = 'rbz'; $auth_pass = '123'; #…
-
1
votes1
answer962
viewsA: View with two or more tables with no link, with different columns and that need to be merged
How to do You can do using the function UNION, thus uniting the results of the 2 tables, and using as subquery: SELECT * FROM ( (SELECT nome as nomefinal, sobrenome, idade FROM primeiratabela) UNION…
-
5
votes1
answer743
viewsA: How not to bring a particular column in SQL using IF and ELSE?
Using the CASE: SELECT (CASE WHEN A.campo1 IS NULL THEN B.campo1 ELSE A.campo1 END) as Resultado FROM tabelaA A LEFT JOIN tabelaB B ON B.id = A.idB You can also use IIF, as said by @Robertodecampos…
-
4
votes1
answer188
viewsQ: Set timeout for specific function
I have a script with several functions. I would like to set one timeout (guy set_time_limit) specific to a function, and if time runs out, it "disregards" and continues running the loop/script.…
-
8
votes4
answers13602
viewsA: Check that the array() is empty with PHP
First of all, beware of the empty, because it can fool you depending on the amounts used. Value Returned Returns FALSE if var exists and is not empty and does not contain a value zeroed. Otherwise…
-
4
votes4
answers169
viewsA: I can’t convert seconds into minutes
How to do A simpler way would be using the function SEC_TO_TIME with TIMESTAMPDIFF: SELECT IDTRANSACTIONS, SEC_TO_TIME(TIMESTAMPDIFF(second, DATEINI, DATEFIM)) AS 'Tempo Médio de Emissão' FROM TEMPO…
-
3
votes2
answers66
viewsA: Search two numbers at once
Another way of doing it would be using HAVING COUNT in subquery. This way, you don’t get trapped in only 2 values ( 34,5 ), can pass more parameters: SELECT * FROM ids WHERE idsubstatus IN (34,5)…
-
5
votes1
answer3138
viewsQ: Why when using ON DUPLICATE KEY UPDATE or REPLACE, do we have change in 2 lines?
Example When executing any of the 2 commands, the message is returned: 2 Row(s) affected Query: ON DUPLICATE KEY UPDATE: INSERT INTO `banco`.`tabela` (`id`, `resumo`, `descricao`, `grupo`,…
-
3
votes1
answer111
viewsQ: Why the "quotes" in the INT data?
In the Mysql Workbench, when we do not enter a record by query, and yes manually, when giving the APPLY, to query is displayed before execution. Example of a query composed of the Mysql Workbench:…
-
8
votes2
answers397
viewsA: MYSQL - Check if PK exists if it does UPDATE if it does not exist
You can use the ON DUPLICATE KEY: INSERT INTO table (id, name, age) VALUES(1, "A", 19) ON DUPLICATE KEY UPDATE name="A", age=19 See working on Sqlfiddle, with ON DUPLICATE KEY and REPLACE.…
-
1
votes2
answers509
viewsA: Annex with phpmailer not enough
First is to know if you are searching in the correct address with the variable $arquivo. As Valdeir said in the comments, it would be $arquivo[tmp_name]. Behold: Documentation $_FILES To forward to…
-
0
votes1
answer32
viewsA: Pick up a user’s first and last entry
One way to do it (which worked due to Mysql limits), would be by subquery: SELECT * FROM (SELECT idusers, MIN(created) mn, MAX(created) mx FROM obusuario GROUP BY idusers ORDER BY MAX(created)) tab…
-
7
votes2
answers385
viewsA: SQL using sum
Correcting The flaw lies in the shape that is using the CASE. How to do: SELECT data, SUM(CASE WHEN QTCxVer <> 0 THEN Quantidade END) as TotalVer, SUM(CASE WHEN QTCxBra <> 0 THEN…
-
5
votes2
answers126
viewsA: Is there any Excel function that returns the body of another function?
You can use the FÓRMULATEXTO() Example: Being: A1 = 10 B1 = 20 C1 = =A1+B1 E1 = =FÓRMULATEXTO(C1) Complementing A simple example using the function to mount a calculation memory: If you use the…
-
0
votes1
answer21
viewsA: Help to import SQL data and use on date
Printing the day of the week: // Array com os dias da semana $diasemana = array('Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sabado'); // Aqui define a data no formato Ano-mês-dia…
-
4
votes2
answers1944
viewsA: View or temporary table?
Temporary tables Using a temporary table in Mysql, allows you to perform tests or services on a transient entity, without worrying about cleaning up the mess afterwards. When disconnecting from the…
-
4
votes1
answer66
viewsA: Sql, sum of several
Considering generic names of tables and fields: SELECT es.nome as estado, ci.nome as cidade, COUNT(pe.id) FROM pedidos pe LEFT JOIN cidade ci ON ci.id = pe.cidade LEFT JOIN estado es ON es.id =…
-
1
votes1
answer20
viewsA: When adding user, it always gives ERROR but ends up adding
You need to reverse the order, because if you have not yet executed the query, you have no changes. Also, you may need the commit depending on how you are using. Example: ... $query->execute();…
-
1
votes1
answer29
viewsA: End every PHP loop
You can add an auxiliary variable: $rows = 2399; for ($i = 1; $i <= $rows; $i++) { $promises[] = $client->postAsync("/localize/1002/consultar", ['form_params' => ['cpf' =>…
-
2
votes1
answer95
views -
2
votes1
answer90
viewsA: How to randomly select a row from each group in Mysql
Solving A way of doing: select (select t2.item from tabela t2 where t2.grupo = t1.grupo order by rand() limit 1) as item, t1.grupo from tabela t1 group by grupo order by rand() Explaining What I did…
-
1
votes1
answer98
viewsA: Consult the names of the pilots sponsored by a Team
As you want the names of the pilots, best use as main table to pilotos, makes it easier to assemble the query. SELECT pi.nome as piloto, eq.nome_e as equipe, pt.nome_p as patrocinador FROM piloto pi…
-
2
votes2
answers79
viewsA: Phpmailer not taking form value
Corrections The way it was, it wouldn’t work because of space, because $_POST is a Array and that way you’re wrong: $_POST ["nome"]; To correct I traded for filter_input thus helps against SQL…
-
2
votes1
answer26
viewsA: Update MYSQL Table Data
It’s missing running its query: $id = 7; $TrocaNome = "Ronaldo"; $TrocaEmail = "[email protected]"; $up = "UPDATE usuario SET nome='$TrocaNome', email='$TrocaEmail' WHERE id=$id"; $exec =…
-
0
votes1
answer84
views -
1
votes2
answers60
viewsA: Data search without formatting sqlserver with select
Consulting Executing a query, in case your bank is only numbers: SELECT CPFCNPJ FROM tabela WHERE CPFCNPJ = REPLACE( REPLACE( REPLACE('111.222.333-00', '.', ''), '-', ''), '/', '' ) Removing the…
-
5
votes1
answer228
viewsQ: A Rigger can "undo/undo" the action that triggers it?
Example scenario I have a table telefones where I have a Trigger that is fired while performing the instruction Insert. Doubt I can use the Trigger for verify a condition and before the return,…
-
2
votes2
answers814
viewsQ: Delete triggers by query
Consultation To consult all the triggers of a database, use: SELECT * FROM sys.triggers Failed attempt I tried to exclude all or some of these triggers contained in the result: DELETE FROM…
-
4
votes2
answers76
viewsA: Select all persons who have birthday date higher than 2000
How to do SELECT * FROM usuarios WHERE YEAR(nascimento) > 2000 How to filter parts of a date Use the functions YEAR, MONTH, DAY who take YEAR, MONTH, DAY of date field: SELECT * FROM usuarios…
-
5
votes1
answer782
viewsQ: How to create Trigger for all tables in a bank automatically?
Example scenario I have a database with 1,000 tables. One table call log. Goal I would like to create a Trigger "standard" in each of these tables, automatically. That one Trigger, whenever there is…
-
5
votes1
answer123
viewsA: LIKE with COUNT in PHP
And this AS faltas does not mean anything because it is giving nickname to a filter field. Use LIKE for data, is a "gambiarra", and that takes more work than doing right. How to work on dates Use…
-
0
votes1
answer54
viewsA: Error while doing select
Motive Error in query occurs because it is not passing the variable between quotation marks in query. And for being a string, it is necessary. Correcting function pegaId($nomeConteudo){ $query =…