<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: WordPress Database Functions</title>
	<atom:link href="http://wpengineer.com/1746/wordpress-database-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com/1746/wordpress-database-functions/</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Wed, 08 Feb 2012 19:48:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: wetwetwafu</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4849</link>
		<dc:creator>wetwetwafu</dc:creator>
		<pubDate>Tue, 07 Sep 2010 02:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4849</guid>
		<description>How can we add a database field where the search query will fetch the search result?

THanks a lot for sharing this.</description>
		<content:encoded><![CDATA[<p>How can we add a database field where the search query will fetch the search result?</p>
<p>THanks a lot for sharing this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Travis Smith</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4731</link>
		<dc:creator>Travis Smith</dc:creator>
		<pubDate>Sun, 01 Aug 2010 03:02:33 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4731</guid>
		<description>Hello,

I have WP 3.0 with MS enabled and I am pull the sites information from my subdomains via $wpdb.

&lt;code&gt;global $wpdb;
$blogs = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT blog_id, domain, path FROM $wpdb-&gt;blogs WHERE site_id = %d AND public = &#039;1&#039; AND archived = &#039;0&#039; AND mature = &#039;0&#039; AND spam = &#039;0&#039; AND deleted = &#039;0&#039; ORDER BY registered DESC&quot;, $wpdb-&gt;siteid), ARRAY_A );&lt;/code&gt;

This gives me an array, e.g. &lt;code&gt;Array ( [0] =&gt; Array ( [blog_id] =&gt; 10 [domain] =&gt; sample1.smithsaga.com [path] =&gt; / ) [1] ...)&lt;/code&gt;

So, I want to add a key [logo] and store it permanently.

So later in my &lt;code&gt;foreach($blogs as $blog)&lt;/code&gt; where I have an input form for $blog[&#039;img&#039;], and then I have &lt;code&gt;$wpdb-&gt;insert( $wpdb-&gt;blogs, array( &#039;img&#039; =&gt; $blog[&#039;img&#039;] ), array( &#039;blog_id&#039; =&gt; $blog[&#039;blog_id&#039;] ) );&lt;/code&gt; but I don&#039;t think this is right. I have also tried $wpdb-&gt;update. So what am I missing or doing wrong? For the full snipit, see http://pastebin.com/U61ME2AU</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have WP 3.0 with MS enabled and I am pull the sites information from my subdomains via $wpdb.</p>
<p><code>global $wpdb;<br />
$blogs = $wpdb-&gt;get_results( $wpdb-&gt;prepare("SELECT blog_id, domain, path FROM $wpdb-&gt;blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb-&gt;siteid), ARRAY_A );</code></p>
<p>This gives me an array, e.g. <code>Array ( [0] =&gt; Array ( [blog_id] =&gt; 10 [domain] =&gt; sample1.smithsaga.com [path] =&gt; / ) [1] ...)</code></p>
<p>So, I want to add a key [logo] and store it permanently.</p>
<p>So later in my <code>foreach($blogs as $blog)</code> where I have an input form for $blog['img'], and then I have <code>$wpdb-&gt;insert( $wpdb-&gt;blogs, array( 'img' =&gt; $blog['img'] ), array( 'blog_id' =&gt; $blog['blog_id'] ) );</code> but I don't think this is right. I have also tried $wpdb-&gt;update. So what am I missing or doing wrong? For the full snipit, see <a href="http://pastebin.com/U61ME2AU" rel="nofollow">http://pastebin.com/U61ME2AU</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sebastien</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4261</link>
		<dc:creator>sebastien</dc:creator>
		<pubDate>Wed, 05 May 2010 15:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4261</guid>
		<description>dameer : in fact it ws a problem of syntax. It works if the syntax is :

if( $wpdb-&gt;get_row(&quot;SELECT post_title FROM $wpdb-&gt;posts WHERE post_title = &#039;$my_post_name&#039;;&quot; ) ) {</description>
		<content:encoded><![CDATA[<p>dameer : in fact it ws a problem of syntax. It works if the syntax is :</p>
<p>if( $wpdb-&gt;get_row("SELECT post_title FROM $wpdb-&gt;posts WHERE post_title = '$my_post_name';" ) ) {</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sebastien</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4259</link>
		<dc:creator>sebastien</dc:creator>
		<pubDate>Wed, 05 May 2010 15:36:48 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4259</guid>
		<description>thx dameer ! but that doesn&#039;t work...</description>
		<content:encoded><![CDATA[<p>thx dameer ! but that doesn't work...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dameer</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4258</link>
		<dc:creator>dameer</dc:creator>
		<pubDate>Wed, 05 May 2010 15:13:33 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4258</guid>
		<description>I guess your dB query is not properly written coz it always returns false...
Try this:
&lt;code&gt;
if( $wpdb-&gt;get_row( &quot;SELECT post_title FROM $wpdb-&gt;posts WHERE post_title = $my_post_name&quot; ) ) { ... }
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I guess your dB query is not properly written coz it always returns false...<br />
Try this:<br />
<code><br />
if( $wpdb-&gt;get_row( "SELECT post_title FROM $wpdb-&gt;posts WHERE post_title = $my_post_name" ) ) { ... }<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sebastien</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-4257</link>
		<dc:creator>sebastien</dc:creator>
		<pubDate>Wed, 05 May 2010 14:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-4257</guid>
		<description>I insert a post with this function 
&lt;code&gt;$my_post_name = &quot;test3&quot;;

// check if title already exists in wpdb
global $wpdb;


if($wpdb-&gt;get_row(&quot;SELECT post_title FROM wp_posts WHERE post_title = &#039;&quot; . $my_post_name . &quot;&#039;&quot;, &#039;ARRAY_A&#039;)) {
echo $my_post_name.&#039; &#124; already exists&#039;;}
else
{
echo &#039;generating new post: &#039;. $my_post_name.&#039; ;&#039;;
// Create post object - in this case just containing one image
  $my_post = array();
  $my_post[&#039;post_title&#039;] = $my_post_name;
  $my_post[&#039;post_content&#039;] = &#039;&#039;;
  $my_post[&#039;post_status&#039;] = &#039;draft&#039;; // or &#039;publish&#039; 
  $my_post[&#039;post_author&#039;] = 1;
  $my_post[&#039;post_category&#039;] = array(228);

// Insert the post into the database
  wp_insert_post( $my_post );
  sleep(1); //wait 1 second between posts
 }&lt;/code&gt;

but my post is insert one time, and two time, nd three time ... 
what can i do ?

i suppose that this line is not avalable :
&lt;code&gt;&quot;SELECT post_title FROM wp_posts WHERE post_title = &#039;&quot; . $my_post_name . &quot;&#039;&quot;, &#039;ARRAY_A&#039;)&lt;/code&gt;

what do you think about this ?

thx</description>
		<content:encoded><![CDATA[<p>I insert a post with this function<br />
<code>$my_post_name = "test3";</code></p>
<p>// check if title already exists in wpdb<br />
global $wpdb;</p>
<p>if($wpdb-&gt;get_row("SELECT post_title FROM wp_posts WHERE post_title = '" . $my_post_name . "'", 'ARRAY_A')) {<br />
echo $my_post_name.' | already exists';}<br />
else<br />
{<br />
echo 'generating new post: '. $my_post_name.' ;';<br />
// Create post object - in this case just containing one image<br />
  $my_post = array();<br />
  $my_post['post_title'] = $my_post_name;<br />
  $my_post['post_content'] = '';<br />
  $my_post['post_status'] = 'draft'; // or 'publish'<br />
  $my_post['post_author'] = 1;<br />
  $my_post['post_category'] = array(228);</p>
<p>// Insert the post into the database<br />
  wp_insert_post( $my_post );<br />
  sleep(1); //wait 1 second between posts<br />
 }</p>
<p>but my post is insert one time, and two time, nd three time ...<br />
what can i do ?</p>
<p>i suppose that this line is not avalable :<br />
<code>"SELECT post_title FROM wp_posts WHERE post_title = '" . $my_post_name . "'", 'ARRAY_A')</code></p>
<p>what do you think about this ?</p>
<p>thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dameer</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-3403</link>
		<dc:creator>dameer</dc:creator>
		<pubDate>Thu, 04 Feb 2010 13:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-3403</guid>
		<description>Just wanted to share something...
Let&#039;s suppose you&#039;ve created brand new table for the purpose of a plugin and want to insert some data. The following will not work:
&lt;code&gt;
$wpdb-&gt;insert( $wpdb-&gt;my_new_table, array( &#039;post_title&#039; =&gt; $mytitle ) );
&lt;/code&gt;
...you have to do it this way:
&lt;code&gt;
$wpdb-&gt;insert( $wpdb-&gt;prefix . &#039;my_new_table&#039;, array( &#039;post_title&#039; =&gt; $mytitle ) );
&lt;/code&gt;
Hopefully people will find it useful.</description>
		<content:encoded><![CDATA[<p>Just wanted to share something...<br />
Let's suppose you've created brand new table for the purpose of a plugin and want to insert some data. The following will not work:<br />
<code><br />
$wpdb-&gt;insert( $wpdb-&gt;my_new_table, array( 'post_title' =&gt; $mytitle ) );<br />
</code><br />
...you have to do it this way:<br />
<code><br />
$wpdb-&gt;insert( $wpdb-&gt;prefix . 'my_new_table', array( 'post_title' =&gt; $mytitle ) );<br />
</code><br />
Hopefully people will find it useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tsalagi</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-3333</link>
		<dc:creator>Tsalagi</dc:creator>
		<pubDate>Fri, 22 Jan 2010 22:14:33 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-3333</guid>
		<description>Thanks for providing these functions. I am very interested in using these types of functions to add more functionality to my site. Where can I learn more information about how to put together such functions and where to use the syntax. For instance your use of get_var at the very beginning has an x and a x but it says get a single variable. What is the x and y for? And where can I learn about your use of absint,, prepare, escape and SET? Are these mysql query techniques or WordPress stuff? I sure would like to find a full fledged tutorial breaking all this stuff down so I can actually learn something other than how to copy and paste.</description>
		<content:encoded><![CDATA[<p>Thanks for providing these functions. I am very interested in using these types of functions to add more functionality to my site. Where can I learn more information about how to put together such functions and where to use the syntax. For instance your use of get_var at the very beginning has an x and a x but it says get a single variable. What is the x and y for? And where can I learn about your use of absint,, prepare, escape and SET? Are these mysql query techniques or WordPress stuff? I sure would like to find a full fledged tutorial breaking all this stuff down so I can actually learn something other than how to copy and paste.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-2957</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Tue, 08 Dec 2009 08:53:20 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-2957</guid>
		<description>Googling $wpdb brings up few resources relating to this rather useful set of wordpress functions. While the wordpress codex does provide some extensive coverage it isn&#039;t laid out as simple as this for those out there who may be new to php or those who need a quick and simple reference list. Nice one.</description>
		<content:encoded><![CDATA[<p>Googling $wpdb brings up few resources relating to this rather useful set of wordpress functions. While the wordpress codex does provide some extensive coverage it isn't laid out as simple as this for those out there who may be new to php or those who need a quick and simple reference list. Nice one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominic</title>
		<link>http://wpengineer.com/1746/wordpress-database-functions/#comment-1919</link>
		<dc:creator>Dominic</dc:creator>
		<pubDate>Mon, 26 Oct 2009 22:55:30 +0000</pubDate>
		<guid isPermaLink="false">http://wpengineer.com/?p=1746#comment-1919</guid>
		<description>Thanks for posting this. I&#039;ve been hand-coding all of my plugin SQL.</description>
		<content:encoded><![CDATA[<p>Thanks for posting this. I've been hand-coding all of my plugin SQL.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

