Posts by jlHertel • 4,733 points
114 posts
-
6
votes2
answers1711
viewsA: Correct way to perform a dynamic UPDATE with PHP in Mysql
You can only enter values and never SQL commands, which includes fields; Example of how you could do your query: $sqlupdate = " UPDATE eventos SET nome = ? , cod_tipo_evento = ? ,…
-
0
votes3
answers21786
viewsA: Array inside array... using push arrays
I believe you must be trying something in this sense: $ar1 = array(1 => array(), 2 => array(), 3 => array(), 4 => array()); $size = count($ar1); /** Adiciona um array novo com os valores…
-
21
votes3
answers59486
viewsA: How to compare dates in PHP?
A quick and easy way to do this is by using the class Datetime along with the method createFromFormat. $timeZone = new DateTimeZone('UTC'); /** Assumido que $dataEntrada e $dataSaida estao em…
-
0
votes3
answers4377
viewsA: window.close does not work
To use jQuery dialogs do as follows: $(seletor).dialog({ // opcoes que eu quero }); To close the dialog you can use the button that is already available in the dialog or use the close command:…
-
1
votes7
answers3667
viewsA: PDO does not connect to Mysql
A quick and easy way to test if mysql is available is by own PDO with its function PDO::getAvailableDrivers() $drivers = PDO::getAvailableDrivers(); foreach ($drivers as $nome) { echo 'Disponivel: '…
-
-1
votes2
answers547
viewsA: Foreach - check and record only those not in the BD
Avoid using mysql_* functions as they are in the process of being discontinued. Instead use PDO or mysqli. An example of optimizing your code would be using Prepared statements: $conn = new…
-
0
votes2
answers225
viewsA: Shell_exec(): How to keep process active when restarting apache?
An elegant solution would be to use the command nohup linux. With this command you can leave a process running in the background and it does not die when you leave. Works very well for ssh sessions,…
-
7
votes2
answers181
viewsA: Why does date_diff count my date range wrong?
As pointed out by @lost in the comments, this is a bug in php. To help solve the problem I recommend that all date calculations in php be done using UTC. That way it would look like: $DataEntrada =…
-
2
votes3
answers1863
viewsA: Return of content by Curl
If I understand correctly you are asking how do you get the return from Curl. In this case I recommend you to use the function curl_setopt, passing through parameter: The Curl connection The…
-
3
votes4
answers4185
viewsA: How to separate values from a php variable?
Another solution would be to separate character by character so that you have each to do what you want. Example, showing each character of a string in a row; $palavra = "teste"; $tamPalavra =…
-
2
votes4
answers6839
viewsA: Block pages using login and Session
This problem is very common and it is up to you to define who can access the page or not. The @Carlos example illustrates how to solve the problem. The logic behind this is: All users have access to…
-
2
votes2
answers151
viewsA: Syntax error in query
Your code would be next to this example below with PDO: try { $conn = new PDO('dns', 'user', 'pass', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $stm = $conn->prepare('UPDATE…
-
2
votes1
answer384
viewsA: Batch Insert using Pdo and transaction
In the case of your code I recommend you move the prepare codes before the while. This way you can go giving Insert in the database to each reading of the file, avoiding having a lot of variables in…
-
0
votes4
answers616
viewsA: Trouble finding prime numbers
An additional recommendation I can give is to improve the performance of the algorithm: When searching for a prime number N the maximum iteration number (in this case variable i) shall be N/2. An…