Jump to content

requinix

Administrators
  • Posts

    15,232
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. So do that.
  2. Are you getting these arrays from a database?
  3. As soon as you discover the thing is "empty", use a header to redirect (check the example). Make sure you do so before there has been output of any kind, including HTML and whitespace before your <?php tags.
  4. What happens if you run the script manually?
  5. "Stopped" meaning what? Cronjob not running? Script not generating backups? Not emailing them to you? Emailing an empty file?
  6. If you have PHP 5.3 you can foreach(static::$db_fields as $field) {Then make $db_fields static.
  7. Then now's the time to start on it. To get the file extension, pathinfo is one method you can use. substr is another (pay close attention to the explanation of the $start parameter). Try some examples to see how they work.
  8. Before you try to do the arithmetic yourself, see if there are other solutions. What happens if you do a mysql_query("SET time_zone = 'Europe/London'");beforehand?
  9. You might be on a system that doesn't support dates that far in the past. You're doing the SQL queries yourself? Do the date formatting in the query.
  10. Use a background-image or a (which supports more than just strings for button labels). Also, Invalid "type".
  11. fputcsv is your friend.
  12. Are there headings? They'd be the first row in that CSV. You should actually see them already.
  13. The "computer repair" ones are all using that computerRepair.php script. That's probably why they all have the same title: the script doesn't try to change it or anything. But without seeing the code we can't do anything but guess.
  14. There's one key step you missed. Take a look at the example and make sure you did everything it talks about.
  15. while($max Probably don't want a maximum of 12 months, right?
  16. Count your columns and count your values. If you have mysqli then you really should be using prepared statements for your INSERT. You're open to SQL injection right now.
  17. You can modify connect_db() so it always returns the same object each time it's called. function connect_db() { static $connection = null; if (!$connection) { $connection = new PDO(/* ... */); // and whatever else } return $connection; }That bit with static $connection (so PHP "remembers" $connection across calls) makes this a singleton. Simply reusing $connection might be enough, but if that variable ever drops out of scope (ie, you use it inside a function or class method) then it'll get cleaned up. On the down side this doesn't make it easy to close the connection, should you want to do that manually at some point. Like if you have a long-running script that only needs the database a little bit early on. If that case arises then you should switch to a full class implementation instead of the simple function above.
  18. If you already got the data earlier then why do you need another query? Can't you run just this query once, get the first row, output it the special way, and output the rest normally?
  19. It's a good albeit generally unnecessary practice to close it when you're completely done. Not after every query. 1. What's mysql_prep() doing? I'm not too confident you need it. 2. That's basically what your code should look like. Is connect_db() returning a new PDO object every time? That's the inefficient part. Create a PDO object the first time and reuse that every subsequent time; the Singleton pattern is typically how that happens. 3. I did find this that explicitly says the connection is closed once the object goes away (eg, with $connection=null).
  20. You "close" the connection after each query? No no. Leave it open and let PHP close it for you. It's quite possible that PDO has coding where garbage collection frees the underlying connection while mysql's coding doesn't (especially considering how it's not object-oriented).
  21. header('Content-type=text/css');should be header('Content-type: text/css');
  22. Because $m is also an array. This isn't rocket science.
  23. It's an array. You need some sort of loop, like a foreach.
  24. The query failed. Run it manually and see what errors you get.
  25. ...Or if you want it to run in the background. Which is what that does.
×
×
  • 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.