0% found this document useful (0 votes)
37 views6 pages

Mpango Wa Project

The document provides example PHP code to connect to a MySQL database and perform queries. It includes code samples to select data from a table, search for values using LIKE, and retrieve and display an image stored in a database table.

Uploaded by

Mazbuti Mazboot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views6 pages

Mpango Wa Project

The document provides example PHP code to connect to a MySQL database and perform queries. It includes code samples to select data from a table, search for values using LIKE, and retrieve and display an image stored in a database table.

Uploaded by

Mazbuti Mazboot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Select example code

<? $username="username"; $password="password"; $database="your_database"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>"; $i++; } ?>

Searching for value


$sql = mysql_query("SELECT * FROM address_book WHERE last_name LIKE 'Stan%'"); while ($row = mysql_fetch_row($sql)) { echo "$row[0] $row[1] $row[2] <br />"; }

and retrieve Image from MySQL database using PHP


Suryanarayan Chandra Step 1. Create database in mysql Syntax: CREATE DATABASES TEST; Step 2: Create table under TEST database Syntax: CREATE TABLE tbl_images{ Id tinyint(3) unsigned NOT NULL auto_increment, Image blob NOT NULL, PRIMARY KEY (id) }; Step 3: create php file in.php to insert image Syntax: <html> <body> <form action=http://localhost/s/in.php method=post> ID: <input type=text name=id />

img path: <input type=text name=img /> <input type=submit /> </form> </body> </html> <?php $con = mysql_connect(localhost,root,"); if (!$con) { die(Could not connect: . mysql_error()); } mysql_select_db(TEST , $con); $sql=INSERT INTO tbl_images(ID, IMAGE) VALUES ($_POST[id], LOAD_FILE($_POST[img])); mysql_query($sql,$con); echo 1 record added; mysql_close($con); ?> Step 4: To retrieve image from database create retrieve.php file Syntax: <?php $img=; $link = mysql_connect(localhost, root, ); mysql_select_db(TEST );

$sql = SELECT image FROM tbl_images WHERE id=2; $result = mysql_query($sql); header(Content-type: image/jpg); mysql_result($result, 0); mysql_close($link); echo <div><img src=.$img./></div>; ?> No related posts.

Share this

Leave a Comment
Name (required)

Mail (will not be published) (required)

Website

Our Services

Web Designing

Web Development Web Hacking Web Promotion Web Security

Connect With Us

Our Associates

Quick Contact

Name* E-Mail*

Copyright 2010 Designed and Developed by SPcits All Rights Reserved.

Online - Click here to get help

http://www.scribd.com/searchdocuments?limit=10&page=23&query=local+area+network+project+report

You might also like