<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jpdemory &#187; LAMP</title>
	<atom:link href="http://www.jpdemory.com/blog/category/lamp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jpdemory.com/blog</link>
	<description>Ressources informatiques</description>
	<lastBuildDate>Fri, 20 Aug 2010 09:49:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP : préparer une requête avec MySQL</title>
		<link>http://www.jpdemory.com/blog/231</link>
		<comments>http://www.jpdemory.com/blog/231#comments</comments>
		<pubDate>Fri, 09 Oct 2009 09:04:06 +0000</pubDate>
		<dc:creator>Jean-Philippe DEMORY</dc:creator>
				<category><![CDATA[LAMP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.jpdemory.com/blog/?p=231</guid>
		<description><![CDATA[Sous PHP, l&#8217;utilisation de paramètres dans SQL peut rendre la tâche fastidieuse avec les multiples concaténations. La fonction sprintf peut simplifier les choses&#8230; Création de la requête SQL en utilisant la fonction sprintf. Cela permet d&#8217;éviter des concaténations fastidieuses. $sql = sprintf("SELECT * FROM clients JOIN commandes ON clients.numclient = commandes.numclient WHERE numclient=%s AND date=%s", [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Sous PHP, l&#8217;utilisation de paramètres dans SQL peut rendre la tâche fastidieuse avec les multiples concaténations.<br />
La fonction <code>sprintf</code> peut simplifier les choses&#8230;<br />
<span id="more-231"></span><br />
Création de la requête SQL en utilisant la fonction <code>sprintf</code>. Cela permet d&#8217;éviter des concaténations fastidieuses.</p>
<p><pre class="brush:php">
$sql = sprintf("SELECT *
FROM clients JOIN commandes ON clients.numclient = commandes.numclient
WHERE numclient=%s AND date=%s",
GetSQLValueString($client,"text"),
GetSQLValueString($dateCmd,"date")
);

$rs = mysql_query($sql) or die ("Erreur : <br/><code>" . $sql . "<code><br/>--<br/>"
. "<span class='alert'>" . mysql_error() . "</span>");
</pre>
</p>
<p>Une fonction très pratique dont je ne connais pas l'auteur. Cette fonction permet de protéger les paramètres passés à la requête SQL.</p>
<p><pre class="brush:php">
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
</pre></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.jpdemory.com/blog/231/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
