MySQL Forums
Forum List  »  PHP

Re: Looking for Rule on quoting
Posted by: Shawn Taylor
Date: August 24, 2010 07:29AM

> Do you have a perferred format?

I try to use heredoc as much as possibe.

http://php.net/manual/en/language.types.string.php

If I have a bunch of different selects I will do all my variable declarations at the head, then build any heredoc to define each query.
This avoids a lot of the single quote/double quote issues and allows you to format a query the way you want to see it and in a way that is readable and maintanable.

Only output to the screen where you have to. Using this tutorial as an example:

I have converted it to:

<?php
// set variable
$brush_price = 5;
?>

<table border="1" align="center">
<tr>
        <th>Quantity</th>
        <th>Price</th>
</tr>
<?php
for ( $counter = 10; $counter <= 100; $counter += 10) {
?>
<tr>
        <td><?= $counter ?></td>
        <td><?= $brush_price * $counter; ?></td>
</tr>

<?php
// close for loop
}
?>
</table>

So you can see that if you wanted/needed to edit the tags you don't have to escape anything and you are free to use double quotes or single quotes for you string parameter values because you are not working inside an echo.

This syntax is a lot easier to read/maintain in my opinion.

The last thing I like to do is have all of my data access be done through functions. That way you can validate any form data on the client side, then put it up to the server, escape it and pass it to a function. This gives you a pretty structured method for debugging. If it's in working with the DB, you go to your lib file and edit the function you are calling. It meas you can reuse your code and you don't have different files interacting differently with the DB than you anticipate.

Good Luck,

Shawn

Options: ReplyQuote


Subject
Written By
Posted
August 20, 2010 11:15AM
August 23, 2010 02:42PM
August 23, 2010 02:44PM
Re: Looking for Rule on quoting
August 24, 2010 07:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.