<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Geek Notes &#187; MySQL</title>
	<atom:link href="http://www.geek-notes.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geek-notes.com</link>
	<description>A web developer's blog: languages, search engines, servers.</description>
	<lastBuildDate>Thu, 12 Nov 2009 01:14:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
		<item>
		<title>How to save search queries on Google Custom Search Engine</title>
		<link>http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/</link>
		<comments>http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/#comments</comments>
		<pubDate>Fri, 17 Nov 2006 18:07:50 +0000</pubDate>
		<dc:creator>Maurizio Petrone</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search Engines]]></category>

		<guid isPermaLink="false">http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engines/</guid>
		<description><![CDATA[
Does anybody out there run a Google Custom Search Engine?
Still wondering how to save your user&#8217;s search queries?
If you host yourself your own CSE, and your server can run PHP/MySQL, here is the solution!
First of all, you have to set up a MySQL table where the search terms searched on your Google Custom Search Engines [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/icons/icon_mysql.gif" width="80" height="80" class="icon" alt="MySQL" />
<p>Does anybody out there run a <a href="http://googleblog.blogspot.com/2006/10/eureka-your-own-search-engine-has.html" title="CSE" >Google Custom Search Engine</a>?</p>
<p>Still wondering <strong>how to save your user&#8217;s search queries</strong>?</p>
<p>If you host yourself your own CSE, and your server can run PHP/MySQL, here is the solution!</p>
<p><span id="more-33"></span>First of all, you have to set up a MySQL table where the search terms searched on your Google Custom Search Engines will be saved: to do so, open your favourite MySQL frontend (like PhpMyAdmin), and run this query:</p>
<p><code>CREATE TABLE `query` (<br />
  `id` int(11) NOT NULL auto_increment,<br />
  `query` varchar(255) NOT NULL default '',<br />
  `datetime` int(11) NOT NULL default '0',<br />
  PRIMARY KEY  (`id`)<br />
) ENGINE=MyISAM<br />
</code></p>
<p>Done? Well. Now, open the page in which you pasted the Google&#8217;s code that displays search results, and add to that page the code that will save data: it grabs search term from the URL:</p>
<p><code>< ?php<br />
/*-----------------------<br />
First part: db connection<br />
-------------------------*/<br />
$dbhost = "localhost";<br />
$dbname = "mylittledb";<br />
$dbuser = "root";<br />
$dbpass = "password";<br />
$db=mysql_connect($dbhost, $dbuser, $dbpass);<br />
if ($db==FALSE)<br />
die("Error while connecting to MYSQL ".mysql_error());<br />
mysql_select_db($dbname ,$db);<br />
/*------------------------------<br />
Read and save the search query<br />
-------------------------------*/<br />
$querystat = mysql_real_escape_string($_GET['q']);<br />
$datetime = time();<br />
if( ($_SERVER['HTTP_REFERER'] == '') AND ( ($querystat != $_SESSION['prev_search']) OR ( ($datetime - $_SESSION['datetime']) > 60) ) ) {<br />
	$insertquery = "INSERT INTO `query` ( `query` , `datetime`) VALUES ( '$querystat' , '$datetime');";<br />
	mysql_query($insertquery, $db);<br />
}<br />
$_SESSION['datetime'] = $datetime;<br />
$_SESSION['prev_search'] = $querystat;<br />
?></p>
<p></code></p>
<p>That&#8217;s all.</p>
<p>This code saves also the time/date of each search, so you can may later analyze searches e.g. per day, per month, or per time period.</p>
<p>Example&#8217;d code <strong>saves queries only if the referer is blank</strong> (i.e. the user did not request the search results page clicking on a link to it, but he has to manually submit the form), and it <strong>prevents multiple page refreshes</strong> (a minute at least has to pass, or the search query has to be different, before the term is saved into database).</p>
<p>If you don&#8217;t want filters, and you want to save right every query, keep just the database connection and the two lines inside the IF statement for the second part.</p>
<div class="sociable"><span class="sociable_tagline"><strong>Bookmark:</strong><span>These icons link to social bookmarking sites where readers can share and discover new web pages.</span></span><ul>
	<li><a href="http://digg.com/submit?phase=2&amp;url=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;title=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="digg"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/digg.png" alt="digg" /></a></li>
	<li><a href="http://del.icio.us/post?url=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;title=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="del.icio.us"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/delicious.png" alt="del.icio.us" /></a></li>
	<li><a href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;title=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="blogmarks"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/blogmarks.png" alt="blogmarks" /></a></li>
	<li><a href="http://co.mments.com/track?url=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;title=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="co.mments"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/co.mments.gif" alt="co.mments" /></a></li>
	<li><a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;h=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="NewsVine"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/newsvine.png" alt="NewsVine" /></a></li>
	<li><a href="http://www.furl.net/storeIt.jsp?u=http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/&amp;t=How+to+save+search+queries+on+Google+Custom+Search+Engine" title="Furl"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/furl.png" alt="Furl" /></a></li>
</ul></div>
]]></content:encoded>
			<wfw:commentRss>http://www.geek-notes.com/mysql/33/how-to-save-search-queries-on-google-custom-search-engine/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>MySQL in a custom dir on Linux</title>
		<link>http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/</link>
		<comments>http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/#comments</comments>
		<pubDate>Mon, 01 May 2006 10:00:53 +0000</pubDate>
		<dc:creator>Maurizio Petrone</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.geek-notes.com/linux/mysql-shared-libraries-on-linux__15/</guid>
		<description><![CDATA[

If you have installed MySQL server in the standard directory /usr/local/mysql, do not read this post. Else, you may want to know
how to use MySQL shared libraries on your Linux system
For organization purposes, I have installed MySQL in /home dir (which is a separate partition), precisely in /home/server/mysql. Thus, I keep mysql/var, directory (which contains [...]]]></description>
			<content:encoded><![CDATA[<img src="/wp-content/icons/icon_linux.gif" width="80" height="80" class="icon" alt="Linux" />
<img src="/wp-content/icons/icon_mysql.gif" width="80" height="80" class="icon" alt="MySQL" />
<p>If you have installed MySQL server in the standard directory <span class="codespan">/usr/local/mysql</span>, do not read this post. Else, you may want to know</p>
<h4>how to use MySQL shared libraries on your Linux system</h4>
<p>For organization purposes, I have installed MySQL in <span class="codespan">/home</span> dir (which is a separate partition), precisely in <span class="codespan">/home/server/mysql</span>. Thus, I keep <span class="codespan">mysql/var</span>, directory (which contains databases) safe from heavy system changes.</p>
<p>My system did not recognized the shared library <span class="codespan">libmysqlclient</span>, that is under <span class="codespan">/home/server/mysql/lib/mysql</span>.<br />
How do you tell Linux <em>&#8220;Hey, you will find the library here, go and use it&#8221;</em>?</p>
<p>Just edit the file <span class="codespan">/etc/ld.so.conf</span> and add the path to your library. Then, reboot or give this command:</p>
<div class="codebox">ldconfig -v</div>
<p>to register new libraries.</p>
<p><span id="more-15"></span><br />
<h4>Compiling programs that require MySQL components</h4>
<p>Another issue you&#8217;ll have to deal with when your MySQL is installed in a non-standard path, is the source compilation and use of programs that require some MySQL components.</p>
<p>For example, I use a <em>C</em> program that has this header on its source:</p>
<div class="codebox">#include &lt;mysql/mysql.h&gt;</div>
<p>I got errors related to paths when compiling this source.<br />
The solution is not changing the source in order to make #include lines match real paths, but consists in telling the compiler where mysql directory is. Compile with such a command line (or change your <span class="codespan">Makefile</span> accordingly):</p>
<div class="codebox">gcc -I/home/server/mysql/include/ -L/home/server/mysql/lib/mysql yourprogram.c -lmysqlclient</div>
<div class="sociable"><span class="sociable_tagline"><strong>Bookmark:</strong><span>These icons link to social bookmarking sites where readers can share and discover new web pages.</span></span><ul>
	<li><a href="http://digg.com/submit?phase=2&amp;url=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;title=MySQL+in+a+custom+dir+on+Linux" title="digg"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/digg.png" alt="digg" /></a></li>
	<li><a href="http://del.icio.us/post?url=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;title=MySQL+in+a+custom+dir+on+Linux" title="del.icio.us"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/delicious.png" alt="del.icio.us" /></a></li>
	<li><a href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;title=MySQL+in+a+custom+dir+on+Linux" title="blogmarks"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/blogmarks.png" alt="blogmarks" /></a></li>
	<li><a href="http://co.mments.com/track?url=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;title=MySQL+in+a+custom+dir+on+Linux" title="co.mments"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/co.mments.gif" alt="co.mments" /></a></li>
	<li><a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;h=MySQL+in+a+custom+dir+on+Linux" title="NewsVine"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/newsvine.png" alt="NewsVine" /></a></li>
	<li><a href="http://www.furl.net/storeIt.jsp?u=http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/&amp;t=MySQL+in+a+custom+dir+on+Linux" title="Furl"><img src="http://www.geek-notes.com/wp-content/plugins/sociable/images/furl.png" alt="Furl" /></a></li>
</ul></div>
]]></content:encoded>
			<wfw:commentRss>http://www.geek-notes.com/linux/15/mysql-in-a-custom-dir-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>
