Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
such a nice boy
Mar 22, 2002

J Crewl posted:

Stupid newbie question here. Is there anything inherently wrong with the below statement, or do I need to include more of a context?
code:
$db->query('INSERT INTO '.$db->prefix.'geocoordinates (name, latitude, longitude)VALUES
(\\''.$db->escape($name).'\\', \\''.$db->escape($latitude).'\\', \\''.$db->escape($longitude).'\\')') 
or error('Unable to insert geocode', __FILE__, __LINE__, $db->error());

When you have a problem like this, you want to know exactly what query you're sending to the database. If you have that, you can put it into the DB shell manually and the DB will helpfully spit out an error that hopefully tells you what's wrong.

So you take the query, stick it in a variable (perhaps $query), print that variable out, and then run the query on that variable. To wit:

code:
$query = 'INSERT INTO '.$db->prefix.'geocoordinates (name, latitude, longitude)VALUES
(\\''.$db->escape($name).'\\', \\''.$db->escape($latitude).'\\', \\''.$db->escape($longitude).'\\')';
print $query;
$db->query($query) or error('Unable to insert geocode', __FILE__, __LINE__, $db->error());
There are certainly other sucky things about that code, though. Constructing table names dynamically is bad. I don't know what those \\ guys are there for; is that for escaping something? The "$db->escape()" function probably does that for you. And using string concatenation to build a query is bad form, anyway. The pros use database abstraction layers, and the totally awesome ones use ORMs.

Adbot
ADBOT LOVES YOU

such a nice boy
Mar 22, 2002

chips posted:

Question about PDFs:

Is there a way to get an image of a particular page in a PDF? I'm interested in adding PDF thumbnails to a website, but can't find any capacity in PHP for reading PDFs rather than just writing them.

Shell out and use ghostscript:

code:
gs -q -sDEVICE=png256 -dBATCH -dNOPAUSE -dFirstPage=2 -dLastPage=2 -r300 -sOutputFile=test.png your.pdf
Tweak that device and page parameters as needed.

such a nice boy
Mar 22, 2002

Treytor posted:

This is an ip logger and checker, which outputs to a text file on the server. Is there a more efficient way to do this? Say for example if my site was getting hammered and my host was complaining about the PHP slowing down the entire server...

EDIT: also, how would I delete expired entries?

Using a database would be more efficient. But if you really don't want to do that, why not set up a cron job to purge the stuff that's older than an hour, and have it run every hour or so?

such a nice boy
Mar 22, 2002

willjo3 posted:

I'm having a problem using the php mail() function. I've been googling and experimenting for two days trying to figure it out to no avail.

Basically, I'm unable to send an email using the mail() function. The interesting part is that our company website (which we bought from a third party) uses the function and it works just fine. To make matters even more fun, my code works on another webserver. I've checked the php.ini sections on mail, and there dont seem to be any relevant differences.

Any suggestions?

If it's a linux box, make sure sendmail is set up correctly. Here's some more information about setting up PHP mail correctly:

http://email.about.com/cs/phpemailtips/qt/et031202.htm

such a nice boy
Mar 22, 2002

illamint posted:

I don't see anything really wrong with my first method, assuming that the interpreter will interpret the string literal as a whole and not instantiate 3 string objects, concatenate them, and return a whole new string object. Is this an OK way of doing it?

Even if it internally does that, why does it matter? Go for readability. Split it into as many pieces as necessary.

edit: drat, minato beat me and his answer is better.

such a nice boy
Mar 22, 2002

Treytor posted:

Could a PHP script be used to ping a server, and redirect to two different pages depending on whether the pinged server responds or not?

Certainly.

such a nice boy
Mar 22, 2002

blunt posted:

:psypop: I could swear to god i'd tried that but low and behold it works perfectly. Much appreciated :)

Use a DB abstraction layer fer god's sake. You're just making life harder for yourself if you don't.

Adbot
ADBOT LOVES YOU

such a nice boy
Mar 22, 2002

zapateria posted:

So what's the easiest way to do this?

Is it possible to move the whole DocumentRoot to the samba share?

Try running the commands as the "www-data" user. It'll show you the same errors that PHP is getting.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply