Skip to content

u/_qdc

In this archive from Jan 2016 to Nov 2017

0
posts
18
comments
0
media
119
score

Everything you stated is developer issue, not a language issue.

You just wrote 4 more paragraphs of developer issues, not language issues. Yes, Wordpress "developers" are the worst but you can also build modern, robust, high performance web applications with PHP7+ and frameworks like Laravel. Blame the developer, not the language.

Most of the "mess" you talk about has been cleaned up in the latest versions. The only thing that still bothers me on a daily basis are the quirky naming conventions and needly/haystack disasters.

If you would remove Drupal, Joomla and WordPress from any ranking index, how big of a slice would PHP still have in the web? I would recon a margin of 5%.

Bullshit argument. People flock to frameworks in any language. How large would Python's share be without Diango/Flask. How much SPAs would be written in vanilla JS if you took out Ember/React/Vue?

4 points

You're 100% correct, but the OP is not using a MVC or OOP structure for this tutorial.

In any modern PHP project, each part of the application should have it's own model that holds the database logic, but I was trying to simplify it to 1 pseudo-model and 1 controller to fit this specific example.

1 points

I was using the OP's code for reference. I would write it like this:

function add_user($client_id, $email, $password, $status, $hash){

   $db = new PDO("sqlite:".__DIR__ ."/../data/db.sqlite");
   $stmt = $db->prepare("INSERT INTO users VALUES (null, :client_id, :password, :email, :status, :hash)");
   $stmt->bindParam(':client_id', $client_id);
   $stmt->bindParam(':email', $email);
   $stmt->bindParam(':password', $password);
   $stmt->bindParam(':status', $status);
   $stmt->bindParam(':hash', $hash);
   $stmt->execute();
   return $db->lastInsertId(); //user id just created
   $db = null;

}

Which is secure.

2 points

IMO, even if you're not using a fully featured MVC framework, it's generally cleaner to keep all your database logic in 1 file.

You could add file called 'db.php' which holds this code (and all your other database statements):

require "../config.php";
require "../common.php";

function add_user($new_user){

try 
{
	$connection = new PDO($dsn, $username, $password, $options);
	
	$sql = sprintf(
		"INSERT INTO %s (%s) values (%s)",
		"users",
		implode(", ", array_keys($new_user)),
		":" . implode(", :", array_keys($new_user))
	);
	
	$statement = $connection->prepare($sql);
	$statement->execute($new_user);
}
catch(PDOException $error) 
{
	echo $sql . "<br>" . $error->getMessage();
}
}

and then in your create.php, you could write

require "../db.php";

if (isset($_POST['submit']))
{

$new_user = array(
	"firstname" => $_POST['firstname'],
	"lastname"  => $_POST['lastname'],
	"email"     => $_POST['email'],
	"age"       => $_POST['age'],
	"location"  => $_POST['location']
);

add_user($new_user);
}
0 points

In my opinion, this plug&play mentality promotes laziness and breeds bad programmers. We've seen the results of it in the past with the whole left-pad drama and npm packages like isArray.

Frameworks and libraries are great, but using them blindly without understanding them is just bad practice imo.

2 points

So you don't give a shit about the quality of the underlying libraries, you just want them to work and deliver the end result they promise?

You sound exactly like my project manager. And I don't mean that as a compliment.

-5 points

If you're serious about switching to i3, do yourself a favor and watch this series: https://www.youtube.com/watch?v=j1I63wGcvU4

It's a 3 part video series that shows you how to turn i3 into a sleek, minimal and nice looking WM. I highly suggest you follow it through to the end. If you don't like some of the stuff he did, you can always undo them afterwards, but you'll learn a lot about tinkering with i3 by following the tutorial.

3 points

Old Thinkpad x220.

Pros:

  • Built like a brick. Insane build quality.
  • Very light & small. 12", fits in any bag.
  • Completely modular. I can strip it down to only the mobo/cpu in less than an hour. Never had another laptop that did this.
  • Linux runs great on it.
  • It's amazing for doing small tasks on the road. Reading emails, browse the internet, watch videos, play music, light development, playing small games like Limbo/VVVVVV/Runescape, etc.

Cons:

  • Some models are prone to overheating and fan whine. The graphics are only Intel HD Graphics 3000, so you shouldnt try to run heavy Adobe software on it.
  • The standard model has a TN display. I don't find this a problem mysef, but some do.
10 points

End of this list.

Back to top

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.