Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. You can set statement_timeout to speed up failure: http://www.postgresql.org/docs/8.2/interactive/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-STATEMENT Another option is to try to take an explicit lock on the resources your transaction needs with the nowait option: http://www.postgresql.org/docs/8.2/interactive/sql-lock.html Deadlock detection timeout is set here: http://www.postgresql.org/docs/8.2/interactive/runtime-config-locks.html But your situation is not a deadlock, so that will not affect you. I'm just pointing it out for completeness
  2. Bingo! Well, some of it makes sense. By "illegal characters" do you mean HTML markup? How exactly do you want to separate it out from the page? For comparison, I would do something like this: $in_data = $_POST['blah']; # Data coming in from user $in_data_escaped = mysql_real_escape_string($in_data); # Escape it for storage in mysql # Then store it in mysql # Later, we fetch it back from mysql.. it will be in the original format as it came from the user. But we want it escaped for safe display $out_data = $row['blah']; # Get it from mysql (assume we did a query earlier) $out_data_display = htmlspecialchars($out_data); # Escape html special characters print $out_data_display; # Safe for display!
  3. You can try a binary search by commenting out portions of code. Start by commenting out around half your code, and see if the error is still there. It's not guaranteed to work, but if it does it's O(log n) rather than O(n) time One question, why do you have "global gsomev;" rather than "global $gsomev;" ? If it's defined, then it doesn't need to be global. If it's not defined, then it should have a dollar sign in front. "Is this common? Is there a way to get the actual line the php engine is actually having a problem with? ._." -- If php knew, it would tell you Yes it's common unfortunately, but you'll learn the patterns. Unterminated strings (like Andy's example), and missing closing braces are two very common patterns leading to errors on the wrong line. Regarding why it works on your pc but not the host.. did you upload the latest version of every file? Exactly the same? md5 hashes can help here to have 100% confidence that you really are running the same code in both places.
  4. Ok, that makes sense. And sessions sounds like a good solution. Is there any problem with storing the url to return to in $_SESSION and redirecting back? As an alternative to Location, you can use a meta refresh tag with a delay. That lets the user see the results of what they did before getting redirected.
  5. Apache2triad is some kind of package right? You'd be better off asking them for support. Based on general knowledge, it sounds to me like your php CLI executable doesn't match your php_curl.dll library. It also sounds like your php CLI executable doesn't even match your C runtime library, which is a more serious problem. Reinstalling php may fix it (make sure you follow all steps in the install instructions, and ask about any you don't understand).
  6. I notice no-one has replied.. I think they are as baffled as I am by your explanation. Can you give some details about your application? Not that I need to know, but it's hard to understand it in such an abstract form. You can even post your scripts if you want (in code tags). Sometimes programmers find code easier to understand than english
  7. Mathy, not sure if this will help, but I hope it does. If you already understand this, then please disregard. Equality in programming is very different from equality in maths. In programming, the "=" sign actually means "assign" or "copy". If you say "$a = $b", then you are saying "Let $a be a copy of $b". If you then modify $a, you will not be modifying $b. $b remains with its original value. In your case, $dat['title'] does not change when you modify $titl, because $titl is only a copy of $dat['title']. So you must copy the final modified value back with the line $dat['title'] = $tit; And similarly for each other value.
  8. Oh.. I get it now. That's actually much easier to do $highlight = 'wacky'; $Topic = 'Today is quite wacky, indeed, it might be said to be weekywackywocky if I may say so. See <a href="/wackybacky.html">here</a> for details.'; $Topic = preg_replace ( "/(?!(?:[^<]+>|[^>]+\<\/a\>))(" . $highlight . ")/is", "<span style='background-color: #CCFF66'>\\1</span>", $Topic); print "$Topic\n"; Now instead of the complicated matching of word boundaries, it just looks for the word "anywhere" (except in html anchors).
  9. Try this: $highlight = 'wacky'; $Topic = 'Today is quite wacky, indeed, it might be said to be weekywackywocky if I may say so. See <a href="/wackybacky.html">here</a> for details.'; $Topic = preg_replace ( "/(?!(?:[^<]+>|[^>]+\<\/a\>))\b(\w*" . $highlight . "\w*)\b/is", "<span style='background-color: #CCFF66'>\\1</span>", $Topic); print "$Topic\n"; \b means "word boundary", and \w means "word character".
  10. Unfortunately, no. Here are two alternate styles. # This one only works for arrays numbered consecutively from 0 $i = 0; $arr_len = count($arr); for ($i = 0; $i < $arr_len; $i++) { print $arr[$i]; print $arr2[$i]; } # This one works for anything reset($arr); reset($arr2); while (list($arr_key, $arr_val) = each($arr)) { list($arr2_key, $arr2_val) = each($arr2); } In both cases, the length of the loop is decided by the length of $arr, in the case of a mismatch in array lengths.
  11. ORDER BY CAST(money AS UNSIGNED) DESC
  12. What data type is money? Try this: ORDER BY CAST(money AS UNSIGNED)
  13. I wouldn't limit yourself with a smallint for the bonus, since it's a monetary value. I can't believe there will be many rows in this table, so saving a few bytes of space is not worth sacrifing expressiveness. The rest looks fine.. it's a little odd to seperate hour and minute, but you can always add them together if you want. FYI, there are functions in mysql to extract the hour and minute part from a time value: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
  14. When you mix AND and OR, you should use brackets to make it clear what you want. Eg WHERE category_id = '".$cat."' AND status = '1' AND ( amount > 0 OR amount LIKE '%unlimited%' ) Is amount a text string that can also hold numbers?
  15. Try this.. SELECT id, itm_desc, itm_link, itm_title, itm_categories, itm_author, itm_date, feed_id, cat_id, archived_on, MAX(score) AS score FROM ( SELECT id, itm_desc, itm_link, itm_title, itm_categories, itm_author, itm_date, feed_id, cat_id, archived_on, MATCH ( itm_desc, itm_title, itm_link, itm_author, itm_categories ) AGAINST ( 'XSS' ) AS score FROM fmc_archive_dev WHERE ( ( MATCH ( itm_desc, itm_title, itm_link, itm_author, itm_categories ) AGAINST ( 'XSS' ) ) AND ( archived_on >1181277356 ) AND ( cat_id =3 ) ) UNION SELECT id, itm_desc, itm_link, itm_title, itm_categories, itm_author, itm_date, feed_id, cat_id, archived_on, MATCH ( itm_desc, itm_title, itm_link, itm_author, itm_categories ) AGAINST ( 'WAF' ) AS score FROM fmc_archive_dev WHERE ( ( MATCH ( itm_desc, itm_title, itm_link, itm_author, itm_categories ) AGAINST ( 'WAF' ) ) AND ( archived_on >1181320556 ) AND ( cat_id =1 OR cat_id =3 OR cat_id =4 OR cat_id =11 OR cat_id =12 OR cat_id =13 OR cat_id =14 OR cat_id =15 OR cat_id =16 OR cat_id =23 OR cat_id =43 OR cat_id =44 ) ) ) AS the_subquery GROUP BY id, itm_desc, itm_link, itm_title, itm_categories, itm_author, itm_date, feed_id, cat_id, archived_on ORDER BY score DESC LIMIT 0 , 300 "the_subquery" is your original query, duplicates and all. All wrapped up in a subquery. Then, wrapped around that is the select which does the grouping. This is the only select that has MAX() in it, and it's matched by the GROUP BY at the very end. The inner selects have no group by, and therefore are not allowed to use MAX(). So the process is: - Generate result set A (XSS) - Generate result set B (WAF) - Union result sets A and B. This union is the result of the subquery - Make results unique on every column except score. For score we take the maximum. This is achieved by the group by and the MAX() combined. Note that the columns appearing in the group by never use MAX(). Those columns are the "key", and the score column is the "data", when you think of it in key and data terms. The grouped by columns have every combination listed, and non-grouped columns get merged together into a single value. - Order by score desc. - Limit to no more than 300 results.
  16. The short answer is no, you can't override functions (well you can, but I wouldn't recommend it). What you can do is make your own "wrapper" function: function my_mysql_query($query) { # Do timing stuff $res = mysql_query($query); # Do timing stuff return $res; } And then replace every call to mysql_query() with my_mysql_query(). You can even do fancy stuff like store time for each individual query in an array, and then dump that array if a debugging flag is set. It's great for seeing which queries are eating up your time. It's called a wrapper function because it wraps around the real function, doing a bit of extra stuff.
  17. I've indented your code to show the problem. You are doing the group by on the individual queries before you union them. This will still give you duplicates. The group by should be around the entire query, including the union, not on each component of the union.
  18. You can create a wrapper for mysql_query, and then do a search and replace over all your files (and make sure to require() it in each file too). Then have the wrapper record timing information.
  19. Here's two options: echo "<a href=\"index.php\">Click Here To Go To The Login Page </a>"; echo '<a href="index.php">Click Here To Go To The Login Page </a>';
  20. You can use a foreach() loop instead of filter_var(). I think it'll be more readable too. There's no need to use such high level programming for such a simple task.
  21. I tested your code, and it work perfectly. I tried color, img and url tags. Maybe the problem is with the string you are passing in?
  22. Here's a simple example $str = "Fluffy Bunnies"; $str = preg_replace("|Fluffy|", "Blood-thirsty", $str); # Now $str is "Blood-thirsty Bunnies" Slightly more complex $str = "<b>Fluffy</b> Bunnies"; $str = preg_replace("|<.*>|", "Blood-thirsty", $str); # Again, $str is "Blood-thirsty Bunnies", but for a totally different reason. .* means "Any string of any characters". So it matches the longest string starting with "<" and ending with ">". These patterns are all identical: "/<.*>/" "+<.*>+" It doesn't matter what you put at the start and end, but it must be the same each time.
  23. You could try: SELECT active, count(*) FROM user_cards GROUP BY active Is "active" not null? If so, then the total will be the sum of Y and N. If not, then you can't use that shortcut.
  24. Do you already have experience with recognizing a single form value and putting that into mysql? Edit: If so, please post your code and we can modify it to handle multiple values.
  25. I don't get what you mean by passing variable values. You can test that variables are passed from a form into php by printing them out at the very start of your script. You can test that they are passed into a function by printing them inside the function. Then you can test that they are passed into your query by printing out the query and looking at it. If the variables make it into the query, and you copy and paste that into phpmyadmin, but you get output you didn't expect, then you know your query is incorrect, and needs to be rewritten.
×
×
  • 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.