« first day (2350 days earlier)      last day (2591 days later) » 

10:00 PM
try not to judge my coding lol
gyazo.com/accdff2444ac3bd7be3e0d3a0c7e33d5 thats what it looks like if u need a better idea
 
bob
@RaduStefanPopescu thought that would do the trick, but no..ugh
 
Okay so what you need to do is instead of having the PHP page output HTML, just put all the necessary information into the array $response
 
oh jesus thats gonna get messy
 
@bob what does it say now? and where does the script get confused? what loc?
 
bob
@RaduStefanPopescu "'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty' " :'|
 
10:06 PM
LOL
gratz you sent an empty query
but at the same time you changed the error message
so we're making progress
does it not give a stacktrace or sth though?
 
bob
@RaduStefanPopescu haha :')
@RaduStefanPopescu line 48
 
i lost your pastebin/hastebin thingy
:(
 
bob
it's ok need to make a new one
 
also they have different line numbers
 
bob
@RaduStefanPopescu pastebin.com/KcEWkipe
 
10:08 PM
well, i guess i needed to remember a bit of PHP
it's a pity to learn a language and forget it
 
@RachelDockter a start is something like...
if ($count > 0) //If there is more than one post
{
	$i = 0;
	$response['posts'] = array();
    while($row = $result->fetch_assoc()) //For every post, display each one
    {
    	$currentpost = array();
    	$currentpost['post_id'] = $row['post_id'];
    	$currentpost['user_id'] = $row['user_id'];
    	$currentpost['post'] = $row['post'];
    	$currentpost['date'] = $row['date'];
    	$currentpost['votes_down'] = $row['votes_down'];
    	$currentpost['votes_up'] = $row['votes_up'];
    	$response[] = $currentpost;
 
ok you're still doing the same thing
i think
what is $dbh
 
Then inside the ajax function you access all that information and create the HTML elements with JS instead of PHP
 
so i know, pls remind me like i'm 5
 
bob
@RaduStefanPopescu new PDO it's in an included file
 
10:10 PM
@bob it's always nice to use encapsulation from classes
when your project gets big you will forget what variable comes from what include
 
@Alesana ok im gonna try it, it looks really complicated but ill make a copy and give it a go ty btw
 
just because PHP lets you do this kind of stuff, doesn't mean it's a good idea
right now, in year 2k17, things have went towards having a bit more structure
 
@RachelDockter It will be easier next time when you when you start with an ajax call instead of trying to switch over
 
exacly thats what i was thinking
 
but still, there is one problem
 
bob
10:13 PM
@RaduStefanPopescu Your right, I need to get my head around that stuff. just not had time to lately.
 
when you say
$dbh->prepare($stmt);
there are 2 ways this code can run
1. when you do $dbh->execute(); or equivalent using the reference of $stmt
or by getting a copy of $stmt at the moment when you actually run $dbh->prepare($stmt)
 
bob
@RaduStefanPopescu that would explain why the query is empty.
 
so figure out if php is pass by reference or pass by value and if in this case (both are valid, STRING is immutable anyway in 99% of programming languages) $dbh->prepare($stmt) gets evaluated right then and there
i mean, from a programming perspective, you could defer the preparation of the statement up until $something->commit is actually ran
but there's this hint
the verb is not ->setPrearedStatement(), but rather actually ->prepare()
 
bob
@RaduStefanPopescu how delightfully cryptic :)
 
@bob what?
 
bob
10:20 PM
@RaduStefanPopescu i'm saying i'm not sure what your talking about
 
it's ok, i might be wrong anyway
db interactions are fucked up everywhere anyway
you need to write imperative code
 
I am really not grasping how Composer should be used
 
^ like what?
 
Wes
left youtube open with autoplay to related videos active, it brought me to jfk assassination conspiracies videos :B
.... i was watching sports videos :B
 
For example, if I have two different packages I am not going to want to require both packages on a page that just uses one, and both again on a page that uses the other.
But require ('vendor/autoload.php'); would autoload all of my packages
 
10:27 PM
@Alesana stop right there, that smells like a different problem
 
Probably so
 
Are you using a front controller?
(single point of entry)
 
No :/
I guess that is my problem
 
The whole tutorial might be worth doing then, it uses composer quite a bit
 
I am going to take a look at it ^^
Now I have looked into OOP and have a basic understanding on controllers and such, but I already wrote all the PHP in my app without using them
Should I just take a step back and write a font controller and move everything to it?
 
ThW
10:31 PM
@Alesana no
 
@ThW that's a relief
 
ThW
it is about separation and encapsulation, define small parts that can be connected and nested.
look around you and define anything in the real world without using an object
 
I don't know if I follow
 
ThW
"putting all the stuff into a class"is not oop
try to create building blocks with generic interfaces
 
Ah okay right.
 
bob
10:36 PM
@RaduStefanPopescu imperative code?
 
@Alesana how much code are we talking about?
 
So I have about 20 php pages in my functions folder
And if I want to, for example, get the IP address I would use in one page include('get_ip.php');, or if I want to get something for an HTML page I would make an Ajax request to functions/get_posts.php
 
Well either way you will benefit a lot from working through the tutorial. If you want to rewrite your app is up to you. If not then at least include a common file or something like that so that you only have to write the composer code etc once
 
ThW
a functions folder is a problem
 
@Alesana this approach is very outdated and hard to maintain
Is it a personal project or work?
 
10:39 PM
I am definitely going to go through the tutorial, possibly for my next project though as I'm very tired of and almost finished with my current project
Personal
 
ThW
it specifies how you implement something but it does not contain a semantic, the naming of the folder does not specify any limit about what to put into it.
 
For redistribution
 
if you are almost finished and it won't need much maintenance then just get it done
nothing worse than 100 almost finished projects (totally not speaking from experience... ahem)
 
ThW
@Patrick true
 
@ThW It has become quite messy
 
10:42 PM
 
But like Patrick says I just have to get it done haha. But what I am thinking is if I have common.php for example and it autoloads all of my composer packages, then in getcountry.php I require('common.php'); wouldn't that be inefficient as it's loading everything just for one function?
 
Also have a look at the clean code and security resources when you have some spare time :)
 
ThW
@Alesana naming is actually a good tool to set limits, avoid names that describe the type 'base', 'object', 'util', 'class', 'function' - use semantic naming like 'events', 'ui/button', ...
 
@Alesana it won't load everything with the autoloader
only when you use something
 
That will come in handy @Patrick
 
10:43 PM
not worth worrying about
 
Ah okay, that makes it better
Now if I am distributing an app with a composer package, it seems that all I need is the "vendor" folder. Is it right to delete the other composer.json, composer.phar, and composer.phar files?
 
always prefer clean code to performance (at least until you are completely sure that something is the bottleneck)
don't distribute composer.phar files
but keep composer.json and composer.lock in there
 
@ThW I do seperate my functions into 2 different folders, which makes it a little bit cleaner
 
ThW
composer.json is your package, composer.lock is the fixed version of you package, both should be in the repo. composer.phar is the tool, can be globally installed and should not be stored in the repo
 
@Patrick Okay I was thinking that might be right
 
10:46 PM
you could also distribute it with the composer.lock and no vendor folder if you require whoever installs it to run composer install himself
depends
 
I don't want to require them to install composer, also it won't be on a repo
 
ThW
@Alesana 2 directories is not really much
 
@ThW Nope it's a mess haha
 
it's 20 files, it can't be that bad...
 
I just checked
It's 38 in one folder and 6 in the other
 
ThW
10:48 PM
@Patrick looking at my current project (Django) - yes it can
 
I'm working on a codebase that is over 10 years old. I have seen things...
 
Haha
So at least the way I am doing it was respectable 10+ years ago?
 
Wrong functions descriptions – #74303
 
@bob in most languages you have to do this bullshit transaction begin and end that you could otherwise associate with an object, it would still be imperative but it would be better encapsulated and easier to work with. Changing it would mean a whole lot of problems for big projects though so they keep it this way. Imperative means that you tell the machine how to execute stuff, think php, java, c, as opposed to sql or lisp
 
bob
@RaduStefanPopescu yeah sorry i already googled it :) in terms of my issue it's 3 in morn i'm retiring for this woeful night.
 
10:54 PM
3 in the morn is when coding really starts
The stars cannot align for good code to be written if there are no stars on the sky
That's a no brainer. Always code wins
 
bob
@RaduStefanPopescu i'll cry myself to sleep :')
 
In your case as well as in most languages when you create a prepared statement, that prepared stmt is sent over the socket to the db which is now waiting for more info to run the query and finally to dump the response and stmt and params and eventually the socket connection
Ppl always seem to forget those things because they don't have a good grasp over how the connection is made
It's still easier in php though
 
bob
@RaduStefanPopescu I need to learn
No easy fix then. damn
 
@RaduStefanPopescu That's mostly because PHP is the only language that bothers dealing with raw queries and has excessive tutorials on how to do direct queries
Most languages use an ORM of some sort, or another layer of abstraction.
 
Php uses orms too
 
11:07 PM
Whew I just remembered my last job still owes me quite a big paycheck
 
I've had experience with Doctrine2, whatever drupal uses(which is completely different because it structures data based on properties rather than entities), jdbc (just as low level as pdo) and hibernate which is 10x as newbfriendly as doctring because threading and caching become an issue
Lazy initialization in hibernate is hell compared to doctrine
It's a good idea to abstract all this stuff, you don't want persistence stuff to spew into your domain logic. Imagine how hard testing would be
 

« first day (2350 days earlier)      last day (2591 days later) »