Jump to content

Brian W

Members
  • Posts

    867
  • Joined

  • Last visited

Posts posted by Brian W

  1. I know that LIKE conditions are slower than a strait equals conditions. In the case that I'm trying to find a particular user's information and I know their first name, I could do something like:

     

    SELECT * FROM users WHERE name LIKE '$name%';

     

    And if I knew their state too:

    SELECT * FROM users WHERE state_id = '$state_id' AND name LIKE '$name%';

     

    The Question is:

    I would expect that because the state condition comes first, MySQL would only run the LIKE condition on the dataset that matched the state which should increase the speed. Am I correct?

  2. Are you working with error_reporting( E_ALL) ? You should be, it helps track down issues. Posting the lines around where the problem is or the entire code (with sensitive data **** out) will help you get helped.

     

    Side note: be sure you to use mysql_real_escape_string on $_POST['suffix'] as well.

  3. exit; kills your application right there... nothing else is processed from that point on. So, your code says that if their is any error messages then simple kill the entire page without spitting out the messages for the user to see. I'd help more, but frankly your code is seems to me that its far from working at all. Please post the functions: field_validator(), checkPass(), and cleanMemberSession(). That should help us with your overall problem.

  4. AbraCadaver, I of course realize I could call the function directly and that would be faster. This issue I have is that I am working with mysqli_stmt::bind_param( string $types , mixed &$var1 [, mixed &$... ] ) which accepts basically limitless params. There are solutions to doing this dynamically, but they all utilize the call_user_func_array which like I said is less than desirable. I don't want to waist too much time spinning my wheels on alternatives, but then again I'm not stuck until I get it done or anything so I'm willing to take some time finding the best solution.

  5. Is there a call_user_func_array() alternative other than eval()? With the shear genius of some of the individuals on this forum, I'd expect that if there is an alternative, someone here would know it. Any tips or insight greatly appreciated. Thanks

     

    Background (blah blah blah)

    I'm being kinda picky on efficiency and performance since I will be looking at possible hundreds of executions a request... so I'd like to avoid using the above mentioned functions since they take ~3x and ~10x longer (according to a this comment).

  6. Drupal uses the $_SERVER superglobal to store connection information (though not the connection object itself that I know of). This does seem to be a valid use as what you are storing is the connection information for the mysql server. Maybe not, maybe Drupal's architects are missing the point too.

     

    Using mysql_connection(), you can use most any of the mysql_* functions without passing in the connection resource which makes it an easy choice... mysqli however isn't as friendly, though its so much faster and (imo) fits in with oop better. From my understanding, using the persistent option with mysqli will cache the connection and reuse the same connection repeatedly until the request is done. If this is true, a factory wouldn't need to access a global connection object because their would be very little resources sacrificed for mysqli to return the cached connection repeatedly.

     

    I'm thinking that using a persistent connection and storing hostname, username, password, and database in $_SERVER is the solution, but then again I'm not all that familiar with building factories... I did see a tutorial using the "singleton" structure, but didn't fully get it I guess. Maybe someone has a link to an awesome singleton for mysqli

     

    Thanks for all the input!

  7. Interesting, $_SERVER is quite bulky...

    My Results

    Base	83144
    putenv	83496
    1	83552
    "1"	83584
    $_SER	94896

     

    Multiple uses of $_SERVER did not increase the memory usage noticeably, but that first time does jump it. So PHP seems to ignore populating it unless you actually use it in your code.

     

    putenv doesn't seem to be required to drop stuff into the $_ENV global. I did this little test this morning:

    <?php
    $obj = new stdClass();
    $obj->name = 'test';
    $_ENV['obj'] = $obj;
    function test(){
        echo $_ENV['obj']->name;
    }
    test();
    ?>

     

    The memory usage is lower than $_SERVER (86632) but if you plan on using $_SERVER anywhere in your code you will end up using the memory.

     

    For a programming convention, not that globals aren't still under scrutiny, is a database connection more of a $_SERVER thing or a $_ENV?

  8. Why (if it is) bad practice to use the $_SERVER array to store variables like the database hostname, username, password, etc... or even a mysqli object?

     

    I know the whole anti lazy coding, but is there another reason not to go about things like this?

  9. I decided to do the benchmarking since no one has replied at this point. I'm not 100% confident that I've got the right idea for benchmarking queries, but I gave it a shot.

    The result: mysqli::multi_query() is faster than mysql_query();

     

    <pre>
    <?php
    $host = "********";
    $user = "********";
    $pass = "********";
    $db   = "********";
    
    $i=0; $result=array();
    $mysqli = new mysqli($host, $user, $pass, $db);
    while($i<200){
        $sql1 = "SELECT * FROM user WHERE id = ".rand(1,9999).";";
        $sql2 = "SELECT * FROM user WHERE id = ".rand(1,9999).";";
        $start = microtime(true);
        $mysqli->multi_query($sql1.$sql2);
        $result[$i++] = (microtime(true)-$start);
    }
    echo (array_sum($result));
    echo "\n";
    echo (array_sum($result)/count($result));
    echo "\n";
    
    $i=0; $result=array();
    mysql_connect($host, $user, $pass); mysql_select_db($db);
    while($i<200){
        $sql1 = "SELECT * FROM user WHERE id = ".rand(1,9999).";";
        $sql2 = "SELECT * FROM user WHERE id = ".rand(1,9999).";";
        $start = microtime(true);
        mysql_query($sql1); mysql_query($sql2);
        $result[$i++] = (microtime(true)-$start);
    }
    echo (array_sum($result));
    echo "\n";
    echo array_sum($result)/count($result);
    ?>
    </pre>

     

    My results:

    0.0062904357910156 //Total for mysqli::multi_query()
    3.1452178955078E-5 //Average for mysqli::multi_query()  - - umm, that aint human speak :-p
    
    4.9394555091858 //Total for mysql_query()
    0.024697277545929 //Average for mysql_query()

     

    According to those results, mysqli::multi_query() is much more efficient. Again, not 100% confident in my benchmarking methods.

  10. A few questions that if I was more knowledgeable about MySQL (such as the query log that I've heard of).

    - Does mysqli::multi_query() make multiple requests to the server or just one?

    - If it is just splitting the queries on the semicolon and then making multiple requests, is it still faster than looping and querying in PHP?

    - Does it take less memory than, lets say, mysql_query() foreach query?

    - Is it faster than, lets say again, mysql_query() looped?

     

    The last 2 I can probably just benchmark myself but I'm hoping someone will know off had.

     

    Background (blah blah blah)

    I'm working on a lean rapid development framework for myself (and maybe others eventually) to use. Much like Cake and other frameworks it does a lot of queries, often times more then you need. The sacrifice of course is performance VS ease of development, but I'm trying to not make a martyr out of my framework :-)

     

    I've observed on many occasions that simple queries can take more time than a complex query  on seemingly random occasions. My understanding is that this is because of the connection, not the real amount of time it took for the server to query. I figure if I avoid multiple requests to the server I will cut down on the time everything takes. My theory is based on the same concept of combining all your CSS and JS files into single files to avoid dozens of HTTP requests which slow down page load time.

  11. In the U.S., you don't need a business license to do what I'm doing legally, although the bureaucrats and IRS (Tax people in the U.S.) would like to make it seem that you do. Regardless, I currently don't make enough money doing what I do to care about filling taxes and when I do start making money, the small fee to register as a Sole Proprietorship (like $75usd processing fee) will be no big deal. That's not enough to pay for a single credit at a University.

    Speaking of cost of education. Unlike in Denmark, Daniel, education can cost you $15k-$40usd a year. In comparison, thats the range in price for a new car from this year. $80k can buy you a middle class house (not rent or down payment, that will get you the whole shebang). So college is no where near free here. Not to start a political conversation, I wonder what you lose out on to gain access to free education in your country.

  12. Money to go isn't necessarily a problem. But I feel that focusing my time on learning more languages and get more clients is time better spent then getting a degree. I looked into SE and that looks like the better direction to go than CS imo, but I still don't think it would make me do better than if I spent the 2-3 years building my business.

  13. First, meant Zend in my last post. Didn't get a chance to correct until now (3:24 am after watching Iron Man 2).

     

    The fact that many programmers do not succeed is likely due to them personally. I knew a guy who was a real wiz in programming, pointed me the right way on a few things... he had horrible personal skill as well as poor hygiene. He always wondered why he couldn't get work, I told him a few times to show up clean and well dressed even to meet a client (let alone potential employer) but he seemed to never do it. Besides him, I've known a few other good programmers with a lot of experience who I wouldn't hire for one reason or another and it seemed other people agreed with me.

    As for me, I may have some quarks that may put off potential clients... but nothing I have ever been told about even by my current client basis. So, I feel confident I could make it as a web developer. If I don't make websites, I'm finding some other career that someone could point out a large number of people who never make enough money support themselves or family.

  14. Wow, thanks guys for the large amount of information. The comparison of SE and CS is even valuable to me and maybe other people looking for information on that topic.

    As for my plan, its the freelance direction.

    I worked for a year at a IT company that offered everything from PC repairs to Web Application Design. I was hired on for the web side and learned a lot while there. I left the position and now have been building up a client basis. Mostly at the moment I am focusing on building a strong portfolio, which as most all of you know pays shit. Unless I'm mistaken, working for yourself always has a slow start but in the end is what I want.

    Even if freelance wasn't my direction, many job posts ask for bachelors||equivalent experience (2-3 years???) and even more often I see them asking for 5+ years experience. I'm coming up on 2 years working experience in programming PHP, 4 in JS+CSS+HTML.

    From what I've read here and what I've seen in the real world, it would appear that the paper is simply to show employers you have the experience but so does work history/portfolios. With freelancing, you could wipe your ass with the degree... toilet paper would feel better and is cheaper.

     

    My plan A was to work my way into the industry, they want me to go about it differently because they think it is *required* in order to be successful. I told her mom about the Zen certificate, she got excited, then I told her about how a guy with that certificate hired me to fix his code... she was a little put off.

    Can I support their daughter? Now that is a good question for me. Right now, no. In the future, I think so. Can anyone right now even with a good paying job really be confident is the future (not just in the current economy)?

     

    For the tenured vets of the freelance programming world, is it uncommon for someone in their first year of freelancing to not make enough money to support someone else?

  15. I'm being pressured from my fiance's parents to go back to school and get a college education. They seem to be under the impression you can't make money unless you have a degree or certificate in something. My previous employer made 500k a year working for himself and he didn't finish high school. My father makes a good deal of money, he owns his own irrigation business, he went to college for biology (not business or anything relevant to what he does). So you can probably figure out my opinion on the topic.

    So, what I want to know is how much does a degree help in programming and website design? Is it more valuable then work experience (time+cost of school + potential gain VS time - pay of customers).

     

    If you can, please respond with your opinion, the level of education you have (if applicable), and how much you made last year roughly (if you are willing).

     

    I guess in a sense I'm performing a study in order to determine my own opinion on the topic.

     

    Thanks.

  16. Windows Server 2007, MySQL 5.1

     

    I installed MySQL several days ago, 3 days ago I tried signing in as root@localhost and I was denied using the same password I had used before. I found some help on resetting my password via init-file which worked. Again, yesterday the same password again stopped working. I tried the same technique with init-file to reset the root password, but I get a message [

    Warning] Changed Limits: ...

    I found a new method using skip-grant-table which allowed me to get in and run

    UPDATE mysql.user SET Password=PASSWORD('MyPassword') WHERE User='root'

    which responds

    Query OK, 0 rows affected (0.00 sec )

    Rows Matched: 1 Changed: 0 Warnings: 0

    Then I've even ran

    flush privileges;

     

    In CMD: "NET Stop MySQL"

    In CMD: "NET Start MySQL" **this time without skip-grant-table

     

    For my example, I would expect to be able to sign in using password "MyPassword", but IT DOESN'T, I'm denied.

     

    Please advise

  17. that means that you have the wrong table name. Check and be sure that in your query you specify the correct name of the table.

    Also, your user data is going to print vertically, but you can deal with that once you've got your query fixed.

  18. Please use code tags... if you don't know what they are, read the forum rules before posting.

    But, I did read your problem and despite the lack of code tags will give you a nudge in the correct direction.

    That error message means that the query had an error, hence making the result un-usable to mysql_fetch_assoc(). Try changing your query execution line to this:

      $result = mysql_query($SQL) or die(mysql_error()); 

    (btw, the above used code tags)

    what that does is say "if mysql_query() returns FALSE because of an error, kill the application and output the error message". Note: mysql_query() will return TRUE if it does not get any results, it will only return FALSE if there is an error in the query.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.