Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/25/2022 in all areas

  1. You don't need to test assignments. Mainly things that are outside of your control such as querying (done by the db server) or a prepare that may not like your query statement, or a query itself that fails to run properly. Of the fetch that may not find anything to fetch.
    1 point
  2. - one doesn't need to user limit 0,1 if only querying for one row. Change to limit 1. - you should verify that everything is performing properly instead of just assuming. Do a test on the prepare, on the execute and the number of rows returned before trying to use the query results. Good practice at all times. Look at examples in the manual. - Another good practice - put your session_start at the beginning of your script. That way it's there and you don't have to worry about it. - If you are only looking to get back 1 row no need to do a fetchall. Change to fetch . - if($row = $stmt->fetch(PDO::FETCH_ASSOC)) - handle the error messages instead of just continuing with your script. - save a function call by simply adding your messages to the error array - $arr[] = 'new message'; The rest seems to me to be secure, but I have yet to use the password verify (or password_hash) so I don't know if that is proper.
    1 point
  3. Example $arr = [ [ 'A', 'Jan. 22, 22'], [ 'B', 'Dec. 25, 21'], [ 'C', 'Feb. 22, 22'], [ 'D', 'Jan. 2, 22'] ]; usort($arr, function($a, $b) { $da = DateTime::createFromFormat('M. j, y', $a[1]); $db = DateTime::createFromFormat('M. j, y', $b[1]); return $db <=> $da; }); echo '<pre>' . print_r($arr, 1) . '</pre>'; outputs Array ( [0] => Array ( [0] => C [1] => Feb. 22 22 ) [1] => Array ( [0] => A [1] => Jan. 22 22 ) [2] => Array ( [0] => D [1] => Jan. 2 22 ) [3] => Array ( [0] => B [1] => Dec. 25 21 ) )
    1 point
  4. COALESCE() comes in useful here SELECT ... FROM tablename WHERE COALESCE(colname, '') = '';
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.