<?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>Rayhan's blog (raynux.com) &#187; MySQL</title>
	<atom:link href="http://raynux.com/blog/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://raynux.com/blog</link>
	<description>Rayhan's Personal Web Blog Site</description>
	<lastBuildDate>Sat, 07 Aug 2010 21:19:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Install Additional softwares by a single command on Ubuntu</title>
		<link>http://raynux.com/blog/2008/11/21/install-additional-softwares-by-a-single-command-on-ubuntu/</link>
		<comments>http://raynux.com/blog/2008/11/21/install-additional-softwares-by-a-single-command-on-ubuntu/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 20:49:15 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[Bash Script]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=45</guid>
		<description><![CDATA[I have created a bash script file to install almost all necessary softwares to run and work on a Ubuntu box. I have tried this script in Ubuntu 8.04 Hardy Heron and Ubuntu 8.10 Intrepid Ibex. Softwares I have placed in this script covers PHP-MySQL development and desktop applications for graphics, multimedia, to Internet applications. [...]]]></description>
			<content:encoded><![CDATA[<p>I have created a bash script file to install almost all necessary softwares to run and work on a Ubuntu box. I have tried this script in Ubuntu 8.04 Hardy Heron and Ubuntu 8.10 Intrepid Ibex. Softwares I have placed in this script covers PHP-MySQL development and desktop applications for graphics, multimedia,  to Internet applications. You can also add your favourite softwares in the script.</p>
<p>File: <strong><em>RayInstall.sh</em></strong></p>
<pre><code>
# RayInstall.sh
#
# Ubuntu Intrepid &amp; Hardy
#
# A very simple Bash Script file to automate installation of necessary
# softwares for PHP-MySQL development and desktop uses in a ubuntu box
#
# This may take several hours or even days depending on your internet connection speed.
#	It tooks 8 Hours for me with about 70-130 KBps of speed
#
# @uses Aplication -&gt; Accesories -&gt; Terminal
#		Now write following command "sudo sh ./RayInstall.sh" without quotes
#		and press enter button on your keyboard
#
# @author ray@raynuxcom
# @licence GPL

#
# For PHP-MySQL Based Development
#

# Install Apache version 2 web server
apt-get -y install apache2 apache2-doc

# Install PHP with necessary modules
apt-get -y install php5 libapache2-mod-php5 php5-cli
apt-get -y install php5-curl php5-dev php5-gd php5-gmp php5-imap php5-ldap php5-mcrypt php5-mhash php5-ming php5-odbc php5-pspell php5-snmp php5-sybase php5-tidy curl libwww-perl imagemagick

# Install MySQL Database server
apt-get -y install mysql-server php5-mysql mysql-gui-tools-common

#Restart apache
/etc/init.d/apache2 restart

# Install Webmin, A web based frontend for linux box.
apt-get -y install webmin

# Install Subversion &amp; Rapidsvn a subversion gui client tools
apt-get -y install subversion subversion-tools libapache2-svn
apt-get -y install rapidsvn

#Restart apache
/etc/init.d/apache2 restart

#Install Doxygen, An documentation tools for PHP Application
apt-get -y install doxygen doxygen-gui doxygen-doc graphviz

# Install Phpmyadmin, A web based mysql administration tools
apt-get -y install phpmyadmin

# Install Java runtime for Eclipse PDT to work properly
apt-get -y install sun-java6-bin sun-java6-jdk sun-java6-jre

# Install Eclipse PDT
# Just download the pdt-all-in-one peckage from zend site
# http://downloads.zend.com/pdt/all-in-one/pdt-1.0.3.R20080603_debugger-5.2.14.v20080602-all-in-one-linux-gtk.tar.gz
# Unpack it in a suitable location.
# run eclipse/eclipse from the unpacked folder and you are done
# Now install Subclipse plugin using eclipse update tools

#
# Graphics, 2D and 3D Modeling Softwares &amp; tools
#

# Install inkscape, An Illustrator alternative
apt-get -y install inkscape

# Install dia and graphical UML modeling tools
apt-get -y install dia

# Install Scribus, An alternative to Adobe Pagemaker
apt-get -y install scribus

# Install Cheese,  Webcam Software, a video and photo shoot application with cool effects for the GNOME desktop
apt-get -y install webcam cheese

# Install QCAD, and linux alternative to CAD Program.
apt-get -y install qcad

# Install Blender, Linux alternative for 3D Modeling
apt-get -y install blender

#
# Misc. Tools
#

# Install Wine, to run windows program
apt-get -y install wine

# Install XChm to read CHM Help file and Manual
apt-get -y install xchm

#
# Multimedia Players and codec
#

# Install GStreamer restricted codec to run mp3 and other media file
apt-get -y install gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad

# XMMS2 Media player
apt-get -y install xmms2 gxmms2

# Install vlc player, An alternative media player. Can play DVD file with title
apt-get -y install vlc vlc-plugin-*

# Install Amarok music player
apt-get -y install amarok

# Install k3b, A dvd burner application
apt-get -y install k3b

#
# Network and internet tools
#

# Install OpenSSH server to access your ubuntu box remotely
apt-get -y install openssh-server openssh-client

#Install gnome-network-admin, not available in default ubuntu 8.10
apt-get -y install gnome-network-admin

# Install Webhttrack, Website copier tools for linux
apt-get -y install webhttrack

# Install kopete instant messenger
apt-get -y install kopete

# install Internet Explorer in Ubuntu (Experimental)
apt-get -y install wine cabextract msttcorefonts

#run the following command manually to install IE
# wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
# tar zxvf ies4linux-latest.tar.gz
# cd ies4linux-*
# ./ies4linux
</code>
</pre>
<p>If you are using Ubuntu on your computer and want to automate the installation process utilising this script then perform the following steps:</p>
<ul>
<li>Create a file name <em>RayInstall.sh</em> in you home folder.</li>
<li>Copy and paste the above code inside the the file and save it.</li>
<li>Open a terminal window from <em>Applications -&gt; Accessories -&gt; Terminal</em></li>
<li>Write the following command</li>
<li><code>sudo sh ./RayInstall.sh</code></li>
<li>press <em>Enter</em></li>
<li>Now it will start installing all the softwares listed in the script and you may need to provide some information during installation process when needed.</li>
</ul>
<p>This script may be helpful for newbies. If you have any comment or suggestion regarding this script please let me know as I am also a newbie in Ubuntu.</p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2008/11/21/install-additional-softwares-by-a-single-command-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Store and Display image from MySQL database</title>
		<link>http://raynux.com/blog/2008/11/20/store-and-display-image-from-mysql-database/</link>
		<comments>http://raynux.com/blog/2008/11/20/store-and-display-image-from-mysql-database/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:09:13 +0000</pubDate>
		<dc:creator>rayhan</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Upload]]></category>

		<guid isPermaLink="false">http://raynux.com/blog/?p=47</guid>
		<description><![CDATA[A basic approach to upload and save image to a MySQL database and then display the image from the database. First you need to create a table in MySQL Database to store the image data. Log into you database and run the following sql command: CREATE TABLE  `images` ( `id` int(11) NOT NULL auto_increment, `name` [...]]]></description>
			<content:encoded><![CDATA[<p>A basic approach to upload and save image to a MySQL database and then display the image from the database.</p>
<p>First you need to create a table in MySQL Database to store the image data. Log into you database and run the following sql command:<br />
<code>CREATE TABLE  `images` (<br />
`id` int(11) NOT NULL auto_increment,<br />
`name` varchar(100) default NULL,<br />
`size` int(11) default NULL,<br />
`type` varchar(20) default NULL,<br />
`content` mediumblob,<br />
PRIMARY KEY  (`id`)<br />
) ENGINE=MyISAM;</code></p>
<p>Once the table have been created, we are ready to write codes. Now create a folder in you webserver named <strong>rayImg</strong> and create image.php and upload.php files inside the folder.</p>
<p>Open the <strong>image.php</strong>, copy and paste the following code and save it.</p>
<p>File: image.php</p>
<pre><code>&lt;?php
	/**
	 * Display image form database
	 *
	 * Retrive an image from mysql database if image id is provided.
	 *
	 * @example to display a image with image id 1, place &lt;img src="image.php?id=1" &gt; in your html file.
	 *
	 * @author Md. Rayhan Chowdhury
	 * @copyright www.raynux.com
	 * @license LGPL
	 */

	// verify request id.
	if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
		echo 'A valid image file id is required to display the image file.';
		exit;
	}

	$imageId = $_GET['id'];

	//connect to mysql database
	if ($conn = mysqli_connect('localhost', 'root', 'root', 'test')) {
		$content = mysqli_real_escape_string($conn, $content);
		$sql = "SELECT type, content FROM images where id = {$imageId}";

		if ($rs = mysqli_query($conn, $sql)) {
			$imageData = mysqli_fetch_array($rs, MYSQLI_ASSOC);
			mysqli_free_result($rs);
		} else {
			echo "Error: Could not get data from mysql database. Please try again.";
		}
		//close mysqli connection
		mysqli_close($conn);

	} else {
		echo "Error: Could not connect to mysql database. Please try again.";
	}	

	if (!empty($imageData)) {
		// show the image.
		header("Content-type: {$imageData['type']}");
		echo $imageData['content'];
	}
?&gt;</code></pre>
<p>Now open the update.php, copy and paste the following code and save it.</p>
<p>File: upload.php</p>
<pre><code>&lt;?php
/**
 * Upload an image to mysql database.
 *
 *
 *
 * @author Md. Rayhan Chowdhury
 * @copyright www.raynux.com
 * @license LGPL
 */

// Check for post data.
if ($_POST &amp;&amp; !empty($_FILES)) {
	$formOk = true;

	//Assign Variables
	$path = $_FILES['image']['tmp_name'];
	$name = $_FILES['image']['name'];
	$size = $_FILES['image']['size'];
	$type = $_FILES['image']['type'];

	if ($_FILES['image']['error'] || !is_uploaded_file($path)) {
		$formOk = false;
		echo "Error: Error in uploading file. Please try again.";
	}

	//check file extension
	if ($formOk &amp;&amp; !in_array($type, array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif'))) {
		$formOk = false;
		echo "Error: Unsupported file extension. Supported extensions are JPG / PNG.";
	}
	// check for file size.
	if ($formOk &amp;&amp; filesize($path) &gt; 500000) {
		$formOk = false;
		echo "Error: File size must be less than 500 KB.";
	}

	if ($formOk) {
		// read file contents
		$content = file_get_contents($path);

		//connect to mysql database
		if ($conn = mysqli_connect('localhost', 'root', 'root', 'test')) {
			$content = mysqli_real_escape_string($conn, $content);
			$sql = "insert into images (name, size, type, content) values ('{$name}', '{$size}', '{$type}', '{$content}')";

			if (mysqli_query($conn, $sql)) {
				$uploadOk = true;
				$imageId = mysqli_insert_id($conn);
			} else {
				echo "Error: Could not save the data to mysql database. Please try again.";
			}

			mysqli_close($conn);
		} else {
			echo "Error: Could not connect to mysql database. Please try again.";
		}
	}
}
?&gt;

&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;Upload image to mysql database.&lt;/title&gt;
		&lt;style type="text/css"&gt;
			img{
				margin: .2em;
				border: 1px solid #555;
				padding: .2em;
				vertical-align: top;
			}
		&lt;/style&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;?php if (!empty($uploadOk)): ?&gt;
			&lt;div&gt;
		  		&lt;h3&gt;Image Uploaded:&lt;/h3&gt;
		  	&lt;/div&gt;
			&lt;div&gt;
				&lt;img src="image.php?id=&lt;?=$imageId ?&gt;" width="150px"&gt;
				&lt;strong&gt;Embed&lt;/strong&gt;: &lt;input size="25" value='&lt;img src="image.php?id=&lt;?=$imageId ?&gt;"&gt;'&gt;
			&lt;/div&gt;

			&lt;hr&gt;
		&lt;? endif; ?&gt;

		&lt;form action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post" enctype="multipart/form-data" &gt;
		  &lt;div&gt;
		  	&lt;h3&gt;Image Upload:&lt;/h3&gt;
		  &lt;/div&gt;
		  &lt;div&gt;
		  	&lt;label&gt;Image&lt;/label&gt;
		  	&lt;input type="hidden" name="MAX_FILE_SIZE" value="500000"&gt;
			&lt;input type="file" name="image" /&gt;
		    &lt;input name="submit" type="submit" value="Upload"&gt;
		  &lt;/div&gt;
		&lt;/form&gt;
	&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>Replace line</p>
<p><strong>mysqli_connect(&#8216;localhost&#8217;, &#8216;root&#8217;, &#8216;root&#8217;, &#8216;test&#8217;) </strong></p>
<p>with<strong></strong></p>
<p><strong>mysqli_connect(&#8216;your host&#8217;, &#8216;your username&#8217;, &#8216;your password&#8217;, &#8216;your database name&#8217;)</strong></p>
<p>in both the file and save again.</p>
<p>You are done. Open upload.php from your browser and upload you desired image and view the uploaded image.</p>
]]></content:encoded>
			<wfw:commentRss>http://raynux.com/blog/2008/11/20/store-and-display-image-from-mysql-database/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>
