Posts by Calebe Oliveira • 4,527 points
40 posts
-
5
votes2
answers163
viewsQ: How to enumerate bad Smells in a software?
I am working on a relatively large system (considered unworkable rewriting effort) PHP that implements in a certain way the MVC architectural pattern and that has (under a higher point of view)…
-
3
votes1
answer1153
viewsA: Pass php session value to Ajax
From what I understand of the question and the code, you’re looking to do a CAPTCHA check. When creating a server side session (with PHP), usually a cookie on the client side is created to store…
-
17
votes3
answers3943
viewsQ: Alternatives to MVC for web applications
Context (TL; DR) When we talk about architectural design patterns, we usually talk about MVC. For the web, we usually use something like the following image: So much so that much of the frameworks…
-
20
votes2
answers11900
viewsQ: How to make a JOIN between two tables of two different databases?
I have the personal data (login, password, name, etc.) of the users on a different server than I will use in a new project. I would like to know how I can cross-reference information between two…
-
2
votes7
answers30383
viewsA: How to dump a Mysql database with PHP?
I ended up arriving at a solution in PHP itself, based on the site script posted by @Gabriel Santos. Follow: class DatabaseDump { private $db; private $host, $user, $pass, $dbname; private $sql,…
-
9
votes7
answers30383
viewsQ: How to dump a Mysql database with PHP?
Currently, to export only the structure of a given database, I use the following: mysqldump -h host -u usuario --no-data --database banco > dump.sql -psenha This generates an SQL file, all…
-
1
votes4
answers1290
viewsQ: How to bring a specific result of an SQL query above the others?
I have the following SQL query: SELECT DISTINCT `user_id` AS `id`, `user_name` AS `name` FROM `users` ORDER BY `id` ASC; That generates the output: +----+--------+ | id | name | +----+--------+ | 1…
-
10
votes5
answers29661
viewsA: How do I know if a column exists in an SQL Server table?
To find out if the column already exists, I thought of the following solution, with count: SELECT COUNT(COLUMN_NAME) AS resultado FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'minhaTabela' AND…
-
6
votes2
answers299
viewsQ: What is a "tick Event" in PHP?
I was looking at some functions in PHP.net, and I came across a function called declare, and in the example, there’s something like: declare(ticks=1); Below is another example: declare(ticks=1); //…
phpasked Calebe Oliveira 4,527 -
20
votes3
answers12960
viewsQ: What is the difference between double quotes and single quotes in Javascript?
Context In PHP, there is a difference between using single and double quotes. In this case, single quotes are for "strings common", and double quotation marks, used when processing string…
javascriptasked Calebe Oliveira 4,527 -
4
votes1
answer717
viewsA: Capture errors and PHP Exceptions
You can capture your exceptions like this with set_exception_handler(): function exceptionHandler($e) { Notificador::logarExcecao($e); throw $e; } set_exception_handler('exceptionHandler'); This…
-
18
votes2
answers9606
viewsQ: How to compile a PHP file?
Is there any way to transform PHP file into bytecode or something similar, and then execute it natively? I need some files on one system to be pre-compiled because of performance in some cases, and…
-
13
votes4
answers18382
viewsA: What is the difference between null and Undefined?
According to Ecmascript documentation, the value undefined is used when a variable does not have a value. The null is used when intentionally meaning that there is an absence of any object value for…
-
8
votes1
answer1071
viewsQ: How to launch my own exceptions with PDO?
When running the line below, in the constructor of my database access class: $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); PDO will report errors by releasing type…
-
7
votes1
answer360
viewsQ: Problem with types in function parameter
When executing the following code: function foo(string $text) { echo $text; } foo('bar'); I get the following error: PHP Catchable fatal error: Argument 1 passed to foo() must be an instance of…
-
5
votes3
answers1058
viewsQ: Createelement() method in PHP
In javascript, I can do: var span = document.createElement('span'); span.innerHTML = 'foo'; span.className = 'bar'; Is there something similar for you to create a ElementNode in PHP, at least with…
-
8
votes6
answers7903
viewsA: When should we allow a column of a table from a database to accept NULL?
I usually use NULL in one column, when I need to use a FK in some situations, and in others, no. Example: I have a table called evento, that records events occurring in the system. Certain records…
-
35
votes1
answer830
viewsQ: What is the difference between "element element" and "element>element" selectors?
I was looking at the code of Twitter Bootstrap, and found this CSS: .table-condensed > tfoot > tr > td { /* ... */ } In the sense of functioning, what would be the difference of placing…
-
4
votes1
answer429
viewsQ: Add "thead" to a table created with createelement
I have the following code, which creates a table, using createElement(): var context = document.createElement('table'); var row; context.className = 'table'; row = context.insertRow();…
-
4
votes5
answers1562
viewsA: Optimize function to include classes also looking in sub-directories
Do so: Archive at the root: new \Root\Classe(); new \Root\foo\Tree(); spl_autoload_register(function ($className) { $className = str_replace('Root\\', '', $className); $className = strtr($className,…
-
12
votes4
answers5034
viewsQ: Set Custom Error 403 Page
I have the following excerpt in my file .htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$…
-
22
votes1
answer16031
viewsQ: Desktop notifications in Chrome with Javascript
I have an application where I need to send notifications to the user, and I would like them to appear on the desktop, as the example below. It is possible to do so with JavaScript? If yes, how? Did…
-
4
votes2
answers2870
viewsQ: Should I adopt the naming standard of my framework or team legacy?
Here in the company, everyone follows a pattern in the projects: All tables should be named in the singular. Examples: "user", "event", "category". And also: The main Primary key is named like this:…
databaseasked Calebe Oliveira 4,527 -
40
votes5
answers10782
viewsQ: What is a Mysql Transaction for?
I was studying some examples of Mysql with PHP and came across as following code snippet: try { $db->beginTransaction(); $db->query('query 1'); $db->query('query 2'); $db->query('query…
-
9
votes2
answers1038
viewsQ: How to use databases in Cakephp without complying with naming conventions?
Cakephp has conventions for naming tables, classes, etc., such as having columns username and password for tables that save users. In my current situation, I have tables that do not obey these…
-
8
votes2
answers673
viewsQ: How to quickly recover a large PHP array?
In the example below, I have a array in PHP with about 128,000 records (Portuguese language entries) that I retrieved from another file, and use in some applications, to compare the indexes as…
-
28
votes6
answers17915
viewsA: How to make a phonetic algorithm for Brazilian Portuguese?
I started making one that works with the following algorithm: Have at the system’s disposal a database with as many words as possible in Portuguese, which can be obtained in dictionaries.…
-
11
votes6
answers36799
viewsA: How to read a text file in Java?
There are several ways to do it. Here are some: Option 1 FileInputStream inputStream = new FileInputStream("dados.txt"); try { String texto = IOUtils.toString(inputStream); } finally {…
-
4
votes2
answers4531
viewsA: Group and add array with PHP
Alternative to the above array_count_values(): $array = array("vermelho", "vermelho", "vermelho", "verde", "azul", "azul"); foreach ($array as $item) { if(!isset($count[$item])) $count[$item] = 0;…
-
2
votes4
answers2688
viewsA: How to package and distribute a web system?
I found a website that brings some alternatives beyond those already mentioned here, as well as the pros and cons of each, bringing also its main resources. Appjs, based on the nodejs; Node-Webkit,…
-
4
votes2
answers4331
viewsA: How to release a protected sub-directory with . htaccess?
Add to configuration file (usually the httpd.conf): Note: <Directory ...>...</Directory> not if added directly to the file .htaccess <Directory /path/to/dir/protected/unprotected>…
-
2
votes3
answers490
viewsA: Scroll bar not hidden in Internet Explorer
Try to use: #div { overflow-x: hidden !important; overflow-y: hidden !important; } or else: $("#div").css("overflow","hidden"); Maybe jQuery can make it work in IE. If the div is taking the whole…
-
21
votes6
answers18042
viewsQ: How to make a Custom Scrollbar?
How to modify a scrollbar div, to appear as in the image example below (Hangouts), instead of the standard operating system scrollbar?…
-
26
votes4
answers2688
viewsQ: How to package and distribute a web system?
I need a certain Web system - including the PHP server itself, as well as Mysql - to be "packaged" in an executable file, thus allowing the layman to use it in a kind of browser of his own. What…
-
2
votes4
answers4212
viewsA: How do I start the next ten?
Try it like this: function aproxima(valor) { if(valor%10 == 0) return valor; var round = Math.ceil(valor); while(round%10 != 0) round++; return round; }…
-
3
votes1
answer197
viewsQ: How to remove a field already added to a 'Formdata'?
The following code inserts files from a field file, in a FormData: var filedata = event.target; // FileList object var i = 0, len = filedata.files.length, file; for (; i < len; i++) { file =…
-
7
votes1
answer716
viewsQ: What are the right practices to handle events in PHP?
I created some classes and an interface to manipulate events for a small MVC application. My intention is to implement the Observer standard, but I do not know if it agrees, since I still confuse…
-
4
votes7
answers3681
viewsA: What are the implications of not declaring variables in PHP?
The more experienced say that it is good to declare variables for numerous reasons. Personally, I’ve never had a problem not declaring variables, except for lack of attention. In most cases, the…
-
5
votes1
answer244
viewsQ: How can I detect and alert that a particular user is sending many messages in a row?
In a chat room, how can I detect and alert that a certain system user is sending many messages in a row (Flood)?
-
12
votes1
answer1368
viewsQ: How to detect that the div was rolled to the end?
I need to know if a certain div was rolled to the end, using jQuery. I’m having problems because the height of the div is not constant. The goal is that the automatic scrolling of the div does not…