« first day (1375 days earlier)      last day (3573 days later) » 

10:07 PM
 
Anyone know how to do a bind_param with a array?
 
@DestinyDawn It is a massive pita
Short answer (if not too late in the project to change your mind) is: use PDO
 
PDO?
 
If you are stuck with mysqli, code sample plz (pastebin.com)
 
it's way too late to change, haha. I already have a website setup and web services for my iOS and Android apps
 
10:15 PM
OK well then let's see the specific case you have
 
Here is my query: SELECT Name FROM Users WHERE ID IN ?
Where ? would be the array of the IDs
It could be from 5 IDs to around 100
 
OK so first of all: you cannot bind a set to a single ?
 
The question marks are confusing :P
 
I agree ^
 
@DestinyDawn another reason PDO is better ;-)
 
10:18 PM
Why can't I just cast the array to a string so it looks essentially like this (1, 2, 3, 4)
 
@DestinyDawn Because it will be treated as a single string param. IN takes a set of values, ( , , ) is just a syntax for specifying that set
If you create it as a string in PHP, MySQL will treat it as a string, not a set
 
@DaveRandom Oh, I see. I don't assume there is an easier way around this is there?
 
Generally what you need to do is "... WHERE ID IN (" . implode(', ', array_fill(0, count($params), '?')) . ")"
 
The array would be $params right?
 
This creates an query that looks like "... WHERE ID IN (?, ?, ?)"
@DestinyDawn Yeh that's your array of values
 
10:22 PM
Wonderful, thank you so much
 
@DestinyDawn It's dangerous to go alone. Take this:
    function bindParameterArray($statement, $parameterArray) {
        $typesString = '';
        $parametersArray = array();

        foreach($parameterArray as $parameterAndType){
            $typesString .= $parameterAndType[0];
            $parametersArray[] = $parameterAndType[1];
        }

        $finalParamArray = array($typesString);
        $finalParamArray = array_merge($finalParamArray, $parametersArray);

        $this->boundParameters = $parametersArray;

        call_user_func_array(array($statement, "bind_param"), $finalParamArray);
 
^ note that this deals with the bind, not the query string generation
But it is a good thing to have nonetheless
 
ugh, all this is just more reason to use PDO instead
 
I am going to my bed - tomorrow ëarly-late time to wake up (7 AM)
Good night All.
 
Goodnight
 
10:24 PM
I had to do something with mysqli recently with binding variables to a resultset. What a pain in the ass
 
I'm reading this over: (".implode(',', array_fill(0, count($UIDs), '?')).")"
How would it fill the array? It would just dump $UIDs?
 
@DestinyDawn It would just be 0, 1, 2, 3, .....until it reached the count of the $UIDs variable.
 
@Danack Ah, lovely, thank you
 
It doesn't sound optimal.
 
@Danack No you are thinking range() I think
 
10:27 PM
@Danack How else would you generate dynamic placeholders in prepared statements?
 
I might end up changing to PDO after a while, but there's an update I need to get done soon.
 
@DaveRandom yep.
 
@DestinyDawn Even with PDO you'd still need a bit of code like that for generating the qstr, the difference with PDO is that passing the values in is sane
 
@DaveRandom Worse?
 
IN() is always tricky to get your head around
 
10:29 PM
I'm used to asp.net so there's a major difference between the two.
 
Just a sec, I have a thing somewhere
Hmm, may not be that useful here actually, very PDO focused
The problem with mysqli's bind is that you have to understand the relationship between the params and the qstr (people always get hung up on a single placeholder for the whole set) and you have to understand how references work in PHP, and you have to understand how cufa violates the pass-by-ref rules
In short: the whole API is borked
 
@DaveRandom cufa?
 
call_user_func_array(), sorry not very clear to people who don't spend their lives writing async and are therefore lazy when writing that out :-P
 
@DaveRandom Ah, yes
I've ran into that pain with mysqli before too
Basically I've used the API just enough to know that I hate it
And I would only ever use it if doing so directly results in food being put on my plate, so to speak.
 
There are sometimes other reasons to use it, but they are few and far between
To me, use of mysqli is a sign of technical debt
(code converted from ext/mysql)
 
10:36 PM
Yea, there was a codebase I had previously worked in where mysqli would have been a big upgrade actually
In regards to getting away from ext/mysql
 
Periodically at work, an error message appears in the logs that says that "mysql_escape_string() is deprecated". The best thing about this is that if you go to the logged file/line, there is no call to the function, so somewhere in the network there is a server with an ancient codebase running, ancient enough that the loggers don't log the server ID, and no-one has a clue which one it is
 
@levi satisfied?
 
sup
 
Not also that this is not a typo, it is mysql_escape_string() and not even mysql_real_escape_string()
 
anyone know why echo $Link = (mt_rand(1,99999999999999999999999999)); always returns 1?
 
10:39 PM
because the second arg is too big
 
yes
 
what is the limit?
 
PHP_INT_MAX
(I imagine)
 
whitch is?
 
No
 
10:40 PM
@DaveRandom What you gave me doesn't seem to be working. I looked into array_fill() here and it seems like it'll only replace that part of the array with whatever string you add w3schools.com/php/func_array_fill.asp
 
Mt_get_rand_max() or something like that
 
So it'll even up saying (?, ?, ?) depending what the length of the array is
 
Please enable error reporting @door
 
@DestinyDawn Do not ever use w3 schools for anything ever ever ever ever
 
10:41 PM
oh wait I just got it. 3v4l.org is eval.org
 
@DaveRandom Noted
 
especially not PHP docs
 
@DaveRandom But it did kinda help. Kinda. I'm using implode(',', array_fill(0, count($UIDs), '?'))
 
@DestinyDawn No you have to pass '?' as the last argument oh typo
 
And it's returning (/)
@DaveRandom It's returning (?)
 
10:43 PM
@Danack It took me so many months before I caught on to that
 
@DestinyDawn Then your $uids array only has one element in it. Can you show a var_dump() of it? I'm guessing it's multidimensional and the outer dimension only has one element
 
@cspray I was about to raise a but report about "EvAluate your code" having weird casing...
 
/me is out. Cya tomorrow
 
@Danack You want to watch those but reports
 
btw by the looks of it enabling error reporting wouldn't help you, but you might want to update your php version @door
 
10:44 PM
@DaveRandom It only does have one value for it. But How do I get it to fill the array with the actual int rather than ?
I added another value now it says (?, ?)
 
@DestinyDawn You don't want to do that
It is doing exactly what it should be doing
 
@DestinyDawn You don't want it to do that, you want the question marks, you bind the values
 
You now have a query string with a dynamic number of parameter placeholders. Now just bind the values to the parameters
 
@cspray Alright...then how do I bind the values for each string? Don't I have to do a foreach loop?
 
You say you are a .net dev, so presuambly you are used to SQL Server?
It's equivalent to bindin params with [name] syntax
(IIRC that's what it the syntax is, I could be wrong)
 
10:47 PM
Yeah, I understand that but we had to bind all of the parameters to the SQLCommand in .net, I think I'm just miss understanding.
 
@DestinyDawn Well, I'm not familiar enough with mysqli to give you what I feel is an accurate enough answer. I know what you're going through is a really common pain point with prepared statements and there's loads of google results about doing this ;)
 
@DestinyDawn No that's where the function @Danack gave you before comes in
 
@cspray I googled for a few hours, trust me, haha.
@DaveRandom Ohhh, alright
Sorry I'm being difficult to work with, guys
 
@DestinyDawn But... you are going to need to manipulate the data I bit I think
One sec
 
Eh, I wouldn't go that far. Much better to work with than a lot of PHP questions I see on SO
 
10:49 PM
I may have an idea that could simplify this a bit
 
Well, off to get the dog some exercise. See you guys later
 
I'm open to anything
 
oh ffs even that is a huge pita
Wait a sec @DestinyDawn I have some code I can steal from something else I wrote a while ago
 
@DaveRandom Will do
Thank you guys so much
I will be right back, have to eat dinner
 
@ircmaxell Do you happen to know of a good starting point for late-bound inheritance check? Like a function to look at?
 
omg mysqli is properly shit
 
@DaveRandom This is not new information.
 
11:49 PM
The horror...
@DestinyDawn ^
 
@DaveRandom switch (true) { <- hahahahahha
Aw man. That's great.
 
inorite
 
Your query token thing is puzzling. Why not just explode on ??
Then again, we can get away with doing that in our codebase because we can just tell each other "well don't do that then" when it breaks.
 
@Charles Need to DELIM_CAPTURE
 
Hmph.
 
11:55 PM
predictably, it's doing weird shit, something's not quite right somehwere
presumably because of stupid refs
did I mention that mysqli is shit?
 
@DaveRandom My god
 
Why are you subjecting yourself to this instead of just doing PDO?
 

« first day (1375 days earlier)      last day (3573 days later) »