« first day (300 days earlier)      last day (4663 days later) » 

12:20 AM
you should have already written it in OOP manner .. preferably using MVC-like separation
 
12:52 AM
Waht does this mean? Invalid parameter number: Columns/Parameters are 1-based
 
dunno .. what is in that line of code ?
 
it throws it on this line $stmt->bindValue($param_key, $param_value);
whole method is:
public function query($query, $params = array())
{
    $stmt = $this->_dbh->prepare( $query );
    if (!empty($params)){
        foreach ($params as $param_key=>$param_value){
            $stmt->bindValue($param_key, $param_value);
        }
    }
    $stmt->execute();
    return $stmt;
}
works fine normal
 
dont do this
 
why? i like this
 
because it's wrong
you are trying to make PDO act like mysql_*
 
1:03 AM
what should i do instead then?
 
that's jsut misguided
 
hmm
 
and i dont have tome now to explain all whys and hows
 
well ok but i like this as i didnt had any object/method that handled my sql queries before this easy/good..
 
here is a hint for you
the User class should not know or care about how and where it is stored
or retrieved
the thing you should look into is called DataMapper pattern
vimeo.com/21173483 , watch the video
 
1:09 AM
it doesnt ! this method is not inside User class but DB class.. User class fetch() are just passing the query and params to this db class method
But ok ill check that out
 
1:54 AM
ok @teresko watched it and read that article.. this is hard time understanding this and really advanced
Could you mention what I should use datamapper pattern to? (in my case)
so my objects dont know anything about the my db ?
and reverse..
the datamapper is actually what i was trying to do with that method above (having something to handle my sqls)
 
 
1 hour later…
3:03 AM
@teresko Ok conclusion on this datamapper, you want me to make it from scratch or include this phpdatamapper.com ? and even with this you would need to do call a method and with a array to say that it should e.g sort by date_created DESC..
 
hi anyone experienced with using php-curl over https
 
@Karem , do not confuse pattern with ORMs which use the same name
a mapper is a separate class
it works something like this:
 
setting CURLOPT_SSL_VERIFYPEER to false does not work
setting CURLOPT_SSL_VERIFYHOST to false does not work too
 
$user = new User;
$mapper = new UserMapper( $pdo , $cache );
$user->set_id( 23 );
$mapper->fetch( $user );
// this would select information about user based on data which is already set
the goal is to abstract the storage mechanism
for example , user data might be separated in two different tables ( authentification and personal details - common practice in huge projects ) , and the fetch method might also gather information about user's groups ( which would be 2 additional tables )
and , except for the construction of $mapper there is no other indication that data is stored in an SQL database
you might later replace the mapper with something that uses information from noSQL database , or remote REST API , or XML file .. or anything
but , Mappers are separate classes
 
so $mapper is the heart
 
3:11 AM
not really
 
but what i dont understand is the fetch you did
 
Mapper is the storage mechanism
 
You set the id on the user
then you fetch to grab info
 
inside it constructs a query , and executes it
 
What does this fetch inside it.. runs a query?
how does it know what to grab for info? i mean where's the actual query
 
3:13 AM
it expects user to have an ID
if there is no ID , it cannot map the user
 
yes it checks if user has an id
 
@teresko and the mapper class doesn't do anything but gather the appropriate data from whatever source and return it?
 
sources , multiple
mapper is responsible for storage
 
ok, fair enough source(s)
 
it stores and retrieves information
 
3:14 AM
gotcha
 
ok well then i got a mapper already just in different class
 
for example if you store a user , it might be 5 queries
 
feels like i am just moving the problem then
	private function _fetch(){
     $params = array(':id'=> &$this->_userid);
     $query = "SELECT up.birthday, up.photo_thumb AS 'avatar',
	 u.id, u.firstname, u.lastname, u.sex, u.bostadsort, u.user_level AS 'isadmin',
	 u.last_access AS 'lastaccess', u.lastname AS 'fullname' FROM users u
	 INNER JOIN users_profile up ON (up.uID = u.id)
	 WHERE u.id=:id";
	 $stmt = $this->_pdo->query($query, $params);

	 $row = $stmt->fetch( PDO::FETCH_ASSOC );

	 return $row;
	}
owh align sucks
 
@Karem , the goal of OOP is separation of concerns
 
3:16 AM
this is what $mapper->fetch() should do instead of $user->fetch()
 
yes
 
or no im sorry i need to edit that method so it doesnt do ->query()..
ok
hold it there then
 
because user should not be aware of the way how it is stored
same way as book in library does not know in which shelf it is
that is not a responsibility of a book , but of librarian
 
how am i supose to do that? If inside get_fullname() i would need to mention that $mapper->fetch..
ohhh
wait
then you want me to do out from your example
 
@teresko - when you use data mapper to save data, do you pass the object or do you just pass arguments?
 
3:19 AM
you pass an object to the mapper
 
So it check for user id in the fetch()
 
@teresko - if I pass an argument, does it mean it's not a mapper?
 
@Karem is there even reason to check ?
@rickchristie , i would say yes and no
 
@teresko where in the get_fullname() or in the fetch()
 
you might pass some conditions to the mapper
 
3:21 AM
Why cant i just have the query() method to the $mapper
this way i can have all queries run in one method
 
@Karem i would move the fetching part to another method ( somethign like init() ) , and check there if ID is set
if it is not set then you are dealing with unsaved user
 
if I use $mapper->update($id, $bookData) ($bookData is an array) instead of $mapper->update($id, $book) ($book is an object) - it's not a mapper is it? It still separates the business logic with the data store logic though.
 
@Karem in general it would be you query method , though i would use different name , because "query" implies SQL , and mapper might be using a different storage medium
 
@teresko ok ok, but lets say i want to use this for my queries to handle, what if i want to select or fetch something else than a query i wrote in fetch(); I would need to have method for each query to execute??
 
@rickchristie , if you looks from the point of class which is using the mapper , how is "update" different from "save" ?
 
3:25 AM
that made it clear
 
@rickchristie , because the class which is using the mapper should not care if it is a new entry or a change in an existing one
 
Ok so my User class should not know how it is storing the data and my mapper class should not know anything about the user class
 
fair point
 
@Karem you can add a method "set_condition" for the mapper , if you want some additional WHERE conditions for selecting data .. but you should examine if you even need it
@rickchristie , the "outer" class is just storing the "book"
 
@teresko - yes, what I want to know is, if it's still legitimate to call the class a mapper if it accepts array of properties as representation of the book data, instead of a book object
 
3:29 AM
@teresko what about the query? thats where my concern is most
 
besides , you should not use random parameters , because Domain Objects usually contain other objects , and when you store it , you will want to store all the related information too
 
@teresko - I think this is the part where I have to learn from experience. Thanks for the heads up
 
@rickchristie no , it isnt , because mapper works with objects
you will need the polymorphic behavior
and you will need ability to pass fake objects for testing
you cannot check if function is using a simple variable
but you CAN check if function is using a variable inside an object ( __get )
@Karem , what about query ?
 
@teresko i really need to understand this right wait i will make a pastebin of my thoughts
 
@teresko - Looks like I need to read up more about data mapper, thx for the help. Laters
 
3:33 AM
to me it seems a simple enough task , because if you are restoring a single user from database , the query will be the same @Karem
@Karem , it will be different if you are selecting a list of users , or searching them , but that would be inside a mapper for UserCollection
 
im just confused now
ill try to write a mapper class
ok from scratch
how would you write the get_fullname() method for User class
I had this:
	public function get_fullname()
	{
		if ( $this->_fullname === NULL )
		{
			$this->assign( $this->_fetch() );
		}
		return $this->_fullname;
	}
but since i cant either $this->_fetch() or $mapper->fetch(); because the User class should not know anything about the storing, im lost
 
oh .. damn
what hell are you doing there
 
im honest.. i dont know
Or yes ofcourse i do now, but i dont know what the goal was.. it makes the connection and the query() method works fine.. then i just move the fetch from User class and thats it
I just dont know how to do it if you say that they must not know about eachother
so i cant even pull out a full name from the user
 
well , User class should not be aware of the SQL connection
ehh ... it feels like i am trying to push this way too fast
the whole "good OOP"
ok , i will try to explain
 
ok so tell me how i should think, $this->_fullname returns the fullname. It needs to bet set by the fetch() and if the fetch is not there inside the User class how can it be set?!?
 
3:48 AM
in previous itteration you passed an PDO object to a User instance
right
 
yes
 
so , if you want now to remove SQL from User class , you will have to pass in a mapper , instead of PDO object
this whole thing is know as "Dependency Injection"
you provide object only with things it will directly use
 
Okay
 
that lets you later replace integral parts of page
if you move from mysql to sqlite or postgresql , then you will only change the PDO object which was passed to all the mappers ( same PDO object , if possible )
that would not affect User class in any way
the "oh .. damn" was a bit on a different subject here : pastebin.com/rD0nn89e
it looks like you have hardcoded the DB parameters inside the class
 
yes
 
3:54 AM
and you have dedicated the class to fetching users
which too makes no sense
 
not really just moved it from the user class
 
> the deeper in woods you go , the more trees you see
 
ok so my goal now is just to make it return fullname of an user
I will have no passing pdo connection to the User class
but a mapper object instead you say which contains the data (fullname)?
is that right or wrong
 
it should work like this : you execure $user->get_fullname();
the method looks it name has been set ( if it is not set , then surname aint there either )
if it is not set , it executes a different method which will load all user details into the object
 
that one tell me about it!
how are this method working?
 
3:58 AM
and then it returns name + surname , and you have full name
 
@teresko - the object I am using is not a data mapper, however it does separate business logic in the model with the data access layer, primarily by having the model ask questions to the data access layer. What should I call it?
 
the method which load the data , checks it ID is set , then takes a mapper ( which was passed in constructor ) , and executes a "fetch" method , while passing $this to that method
if ID is not set , it throws an exception
 
is that method inside the User class?
 
fetch ?
no , it is a method inside Mapper
public
 
no the method that checks if id is set
and then it executes mapper->fetch
no the method that checks if id is set
 
4:02 AM
protected function _load()
{
    if ( $this->_id === null )
    {
         throw new Exception( 'something went wrong !');
    }
    $this->_mapper->fetch( $this );
}
 
	public function get_fullname()
	{
		if ( $this->_fullname === NULL )
		{
		    $this->loadData();
		}
		return $this->_fullname;
	}
    private function loadData(){
        if ( $this->_userid == NULL )
        {
            # load mapper->fetch() here ?
        }
    }
 
something like this
 
cant make fixed font so it aligns :s
Ok
mapper is what you got from the constructor ?
_mapper is set from what you got in the const?*
why do you pass $this ?
 
ehh.. it is actually a bit more complicated than that
 
then what?
 
4:08 AM
well , in this case you are passing $this to the mapper , because mapper will get data and stor it in the object
this whole structure is actually building up to a Model from MVC
if you know what that is
 
i dont ofcourse
what should the mapper do with $this ?
and how does Mapper class set the variables that is inside User class
and whats more complicated (makes me worry) :P
 
@Karem , wasnt the assign() method public ?
 
yes
 
the mapper will get ID from object which was provided to it , get data and assign values to it
 
oh right
 
4:14 AM
though i suspect , that i begun pushing in wrong direction here
 
id of the user?
 
here is where is suspect i drifter into some bullshit
User class does not need the mapper
at all
damn
 
serious?
....
once again i thought i was getting it
 
no no
you were right
passing $this is stupid
$user = new User;
$mapper = new UserMapper( $pdo );

$user->set_id( 42 );
$mapper->fetch( $user );
echo $user->get_fullname();
@Karem , this should make more sense
 
yes because i thought also why did he say before not having it inside User class the ->fetch
and then doing the load() with it now ..
okay
class userMapper{
    private $_pdo;

    function __construct( $pdo ){
        $this->_pdo = $pdo;
    }
    public function fetch($user){
        $params = array(':id'=> &$this->_userid);
        $query = "SELECT up.birthday, up.photo_thumb AS 'avatar',
        u.id, u.firstname, u.lastname, u.sex, u.bostadsort, u.user_level AS 'isadmin',
        u.last_access AS 'lastaccess', u.lastname AS 'fullname' FROM users u
        INNER JOIN users_profile up ON (up.uID = u.id)
         WHERE u.id=:id";
 
4:26 AM
emm ... what is foreach doing there exactly ?
aint you expecting just a single user ?
it would be an array with only one element
 
yes but i thought this goes through it and assign
or no
theres array in assign
my bad
 
just use $array = array_shift( $data );
 
where=
 
that function will retrieve first element from result array
( i found that there can be some issues , if you just use $array = $data[0]; )
i do not recall what was the reason , but it was something annoying
 
i just look up the function it says it passes the first array
or no
the first will go to $array
ok got it
 
4:36 AM
how to get login username in .htaccess?
 
@teresko pastebin.com/VJL5Csdu and still not working
 
define "not working" ?
 
no output
 
$params = array(':id'=> &$this->_userid);
wtf
fist of all , stop using references
 
just tried type hinting the assign() it says string given
whats references?
 
4:45 AM
whoever told you to write this should be hanged by dangly bits
& is a reference
 
yeah someone actually told me
ok i got it working now
i removed the array_shift.. apparantly it strips the array to one field
 
hehe
my bad
 
finally it works !
06:47 am
:P
 
did you get the "SQL antipatterns" book ?
 
you link me but i have not bought it
 
4:48 AM
buying books takes time
 
didnt mean literally
 
russian girl is looking for me on that site
thanks.. downloading
 
a small hint for you to think about
in the database you should have same name for same column in all the tables
 
$test = preg_replace('/\r\n/','<br />','los angeles\n\n\n \n CA');
echo $test; is this correct ???
 
4:51 AM
i do have it already
uID is userid ok you mean i could use the id instead
 
if you have table Users , and it has a primary key user_id , then in in your example in user_profiles that column should have the same name
 
okay true.. i have id and uID different names
 
in other words "stop using id as default name for primary key columns"
 
yeah.. im used to it
Theres one thing remain i need to ask you teresko
 
i would even go so far to say that the tables primary key should hint the name of table
 
4:54 AM
hey anybody know the ans of my que???????????
 
so that you do not need to looks where sID column comes from .. is it in table Sites or Sales or Superusers
 
haha, i get your point
 
as added bonus then you can make query like this :
SELECT Users.name , Groups.name FROM Users
LEFT JOIN UserGroups USING ( user_id )
LEFT JOIN Groups USING ( group_id )
WHERE Users.user_id = 42
for a situation where many users can be in many groups
 
Nice
Right now 80% of my pages sqls is $connect->prepare("query") and 20% is remade to $db->query("query"); didnt got to do more before you stopped me.

What should I do instead for all these? If i have a mapper for it, it would be smiliar to the $db->query() method, wont it? where you just insert the query and $params if theres any needed to be bound
And if i do a mapper with methods for each sql.. that will be alot of methods
 
i would use ->prepare() whenever it is reasonable
because it creates additional protection against injections
 
4:59 AM
yeah yeah
but the method query() (dont do mistake by the name) is preparing it too and bind it
 
and you should not dynamically build queries , if you are gonna use them in prepare()
because prepared queries get cached
 
I dont know they do the same, it looks nicer in the code you can replace

$stmt->bindvalue();
$stmt->bindvalue();
$stmt->bindvalue();
$stmt->execute();
how is dynamically build queries?
 
it's when you are creating query on the fly
usually in the WHERE conditions
 
like in search conditions?
if(set) $query . = " AND .." ; ?
 
yeah
 
5:03 AM
what should you do then about those queries?
 
honestly , i don't know which is the best way
 
hehe good answer
ok so what was your answer for what i should do about all the queries?
 
but i prefer security over optimization , so i would try to use prepared statement , if possible
 
do it same as before? inline sql connections?
 
no , you can execute simple queries from PDO too
you use the same object
it's jsut that if you are nto using prepared statements ,then you will have to manually protect against injections
i think PDO had method escape()
 
5:07 AM
i think you misunderstood :P
 
then again , i dont really see the point in site having a search built in
 
forget search
Lets say i have other stuff on my site
SELECT id FROM pages WHERE show=:value
this will require me to do:
$stmt = $connect->prepare("SELECT id FROM pages WHERE show=:value");
$stmt->bindValue(":value", $value);
$stmt->execute();
 
yes , it would
 
The method i made hardcoded with the bindvalues(), remember? I could do:
$params = array(":value", $value);
$stmt = $db->query("SELECT id FROM pages WHERE show=:value", $params);
the query() does exactly the same as above, and thats why it looks nicer inline
So if you has 3 selects under each other it would be 3 lines instead of 12 (example)
 
not really , because you are exposing SQL to the layer which should not know about it
 
5:11 AM
 
what layer?
 
you can do something like that internally
 
how?
 
lol
i think i understood what you are aiming for
did you actually read manpage for PDOStatement::execute() method ?
look at Example #2
 
!!!
lol
 
5:14 AM
was that it ?
 
yeah
nice didnt know that
 
the benefit of PDOStatement::bindValue() is that it lets you define type of value
 
ahh i see
 
is it a string , an integer , how large it has to be
 
if you define it, will it make any faster?
 
5:17 AM
not , that's not it
 
what does it help define the type then
 
it will just make sure that data you are passing there is actually an ID
and not some string
you might have notices that you do not put quotes around WHERE name = :name
 
yes
oh so if it was a string
it would have 'asd'
 
not really
 
what does it do without the define? auto define? :P
im out of guesses hehe
 
5:20 AM
trick is that you send the query and data separately
default type is PDO::PARAM_STR
search for "PARAM"
 
i see
Ok thanks for your help, going for sleep now when the sun is lighten in the room
 
 
1 hour later…
6:30 AM
I'm doing a simple state engine / parser. So far, I'm making it to parse data into lines, but it will be parsing the data lines into cells as well.
$lines = array(array());
	$cells = &$lines[0];

	for($i=0; $i<strlen($data); $i++){
		// get character at current and next pos
		$cur=$data[$i];
		$nxt=isset($data[$i+1]) ? $data[$i+1] : '';
		// if character is CRLF, move to next line in output array
		if($cur.$nxt==CRLF){
			$lines[]=array();
			$cells=&$lines[count($lines)-1];
			$jump=1; // do not parse next character
			continue;
		}
	}
Any suggestions on performance? What about my use of references ($cells variable) does is sound like a bad idea?
 
just use if else
den zoom you're good to go.
 
 
1 hour later…
7:41 AM
(mysql) tried "SET @a = 1; SHOW VARIABLES;", but didn't see my variable, is VARIABLES the wring keyword?
 
 
1 hour later…
Tek
lol @ Brian's answer
 
jQuery fanboyism is as worse as CodeIgniter fanboyism
2
 
9:27 AM
What about Cake?
 
@Robik I didnt notice much Cake fanboyism on SO yet
 
What a relief
 
10:02 AM
Really bad User Interface ... Do I choose OK to cancel my account or Cancel to keep it? http://t.co/vNwdUFL
 
10:20 AM
@Greg cancel the cancel by clicking cancel?
 
good unusability :)
 
10:58 AM
Are you sure you want to delete your account? [OK]
@Gordon The only thing I love in Cake is its name.
 
PiePHP
 
Then again, it would be a huge distraction on development ("I wonder what cakes are serving today in the cafe below...")
 
@ChristianSciberras Got the same problem whit cookies?
 
Yeah :(
I end up staring at cookies icon in firebug :(
mmmm...cookies...pie...cake
 
I use to live beside the cookie faktory "Göteborgs Kex", and everymornig when i was on my way to school, i could smell the new baked cookies
 
11:08 AM
@PugganSe oh god...
During my way to school, I used to pass in front of a bakery. Strong smell of baked bread :)
 
cheers
 
But cookies...uh...I'd take my day off. lol
Hey @KamilTomšík. Hello
 
@ChristianSciberras it's smelled good, most of the days, but you wanted to eat cookies every morning :-(
 
btw: 5.3.5 was released?
 
@KamilTomšík of what? PHP is at 5.3.6
 
11:10 AM
ah :-D
 
lol
or 5.4a1 if you want to :P
 
yeah, I have that on desktop
 
What's DTrace?
 
hmm, i got the option to install dev-lang/php-5.5.0_pre201105211430
 
something like top :-D
 
11:13 AM
oh..ok. Hmm, kind of like strace?
 
@ChristianSciberras we are at alpha 3 for 5.4 already
 
dunno
@Gordon cool!
 
@Gordon But it ain't public is it?
Then again, it's strange Alpha 1 is actually public.
 
Gentoo Stable: 5.2.14, 5.2.17, 5.3.3-r1, 5.3.6, Gentoo Masked: 5.3.6-r1, 5.3.7_rc2, 5.3.7_rc3, 5.3.7_rc5, 5.4.0_alpha1, 5.4.0_alpha3, 5.5.0_pre201105211430
 
emerge php :-D
 
11:27 AM
@KamilTomšík to quick, lets do a "emerge -e @world" :-p
 
11:38 AM
@ChristianSciberras php.net
 
11:58 AM
Wow! We have about field on chat profile! :D
 
@Robik Yup! its cool isn't
 
They didn't mention about it :(
 
there is lots of undocumented stuff.
 

« first day (300 days earlier)      last day (4663 days later) »