Hi all,
These are some really simple Q's for PHP and MySQL, but I can't seem to find any references off Google that'll give me a definitive y/n answer.
PHP Q: Basically here I'm trying to pass an e-mail address using the cleartext URL form get() method, i.e. http://mydomain.com/myPHPscript.php?email=passed_email. The question here is will the special character @ inside an email address create any confusion when using get()?
MySQL Q: This question is regarding the SELECT function, i.e. SELECT * FROM mytable WHERE some_parameter. The question here is what are SELECT's return values? I've Googled the crap out of this one, and it seems it either returns the row information that matches the WHERE critera, or it returns FALSE if the query is invalid - however, all examples that I've found of the invalid query have been syntaxtical, meaning that if mytable didn't exist or some other WHERE parameter was messed up, it'd return FALSE. What happens if all parameters are correct but nothing was found, does it return NULL?
Thanks,
card
Some simple PHP and MySQL Q's
Moderator: General Moderators
Re: Some simple PHP and MySQL Q's
mysql_query would return a resource, you should put this into mysql_num_rows to check the number of returned rows. If mysql_query returns null you can be happy the query itself is invalid, not the results.
Re: Some simple PHP and MySQL Q's
thanks mike, that's what everyone was doing in the tutorials, and this was my original thought, but i figured there had to be some way to do this check either internally to SQL or without too much additional code.mikemike wrote:mysql_query would return a resource, you should put this into mysql_num_rows to check the number of returned rows. If mysql_query returns null you can be happy the query itself is invalid, not the results.
i'm really concerned with efficiency and number of op's - basically i'm multiplying every op by 100mil or 1bil, so anything that i can do to cut down on processing is something i'm interested in.
actually, if you or anyone knows of some good websites that describe operational efficiency, that'd really help me out.
case in point, take the LIMIT clause that can be used within SELECT - does LIMIT have to search through the entire table, i.e. n rows, before returning anything or does it stop once the LIMIT parameters are satisfied? additionally, with two parameters, does it skip to the correct index or does it still have to count up?
i.e...
LIMIT x - takes the first x rows; let x = 10 and my table have n = 100 rows, how many rows does it search? 10 or 100?
LIMIT x,y - takes x offset with y rows after that; let x = 10 and y = 20 (i.e. it would return rows 11-30 to SELECT), how many rows does it search? 20, 30 or all 100?
other case in point, take the WHERE and SELECT - does WHERE prevent the reading of an entire row's data until the WHERE comparison is satisfied, i.e. WHERE dog = husky, if a dog = labrador, would that row's info corresponding to labrador be read? additionally does SELECT only read whatever it's told to select, or the whole row's data and then trim it down? i.e. SELECT table1.name, would only name be read and returned or the whole row then name returned?
cheers,
card
Re: Some simple PHP and MySQL Q's
Query optimization is a pretty complex topic and doesn't yield to simple answers (nor do I have all the answers!). The usual attitude is "if you are dealing with databases large enough to be concerned about this, you really need to hire an expert (I know several) or spend a lot of time studying the internals of how MySQL database engines work." That's a little blunt, but there's a lot of truth in the statement. You can certainly read up on it, including articles like this: http://www.devshed.com/c/a/MySQL/MySQL- ... -part-1/2/ or this: http://www.databasejournal.com/features ... ndexes.htm. Although those probably won't answer your questions directly, you will begin to get a feeling for how complex the internals really are.
Re: Some simple PHP and MySQL Q's
thanks jack, i've been looking up additional websites and from the (lack of) information, i wagered this was also probably the case.
i'm trying to one-shot my database queries, writes, php files/functions, etc. though i know that's an unrealistic scenario, i want to at least be able to jot down some notes in comments for future reference later (i.e. can't clean up the house in one day, but at least i'd like to organize it all into a list so i know what all left there is to do).
i've written some E-R diagrams and tried to be as thoughtful as possible, but as you mentioned, this stuff is probably best left up to the experts and some of it looks to be SQL/server dependent as well. i don't want to spend a whole lot of time on this, but i also don't want to look back in a few months and realize a stitch in time really could've saved 9
cheers,
card
i'm trying to one-shot my database queries, writes, php files/functions, etc. though i know that's an unrealistic scenario, i want to at least be able to jot down some notes in comments for future reference later (i.e. can't clean up the house in one day, but at least i'd like to organize it all into a list so i know what all left there is to do).
i've written some E-R diagrams and tried to be as thoughtful as possible, but as you mentioned, this stuff is probably best left up to the experts and some of it looks to be SQL/server dependent as well. i don't want to spend a whole lot of time on this, but i also don't want to look back in a few months and realize a stitch in time really could've saved 9
cheers,
card
Re: Some simple PHP and MySQL Q's
Well, you can certainly do a lot to improve performance with wise choice of indexes and analysis with built-in MySQL tools like the ANALYZE and EXPLAIN directives. But I know a couple of guys who make their entire living from consulting in the area of database scaling and optimization. It's pretty much beyond my skill level.