<?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>php and mysql connection Archives -</title>
	<atom:link href="https://mitindia.in/tag/php-and-mysql-connection/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/php-and-mysql-connection/</link>
	<description></description>
	<lastBuildDate>Sat, 09 Jul 2016 12:53:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>php and mysql connection Archives -</title>
	<link>https://mitindia.in/tag/php-and-mysql-connection/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>PHP Database connection</title>
		<link>https://mitindia.in/php-database-connection/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Thu, 30 Jun 2016 08:23:21 +0000</pubDate>
				<category><![CDATA[PHP-MySQL]]></category>
		<category><![CDATA[php and mysql connection]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=199</guid>

					<description><![CDATA[<p>Database connections using PHP and MS Access 1. Display list of records from MS Access  database to PHP web page. (for this example you need to create a DSN from control panel, to create DSN click here) &#60;html&#62; &#60;body&#62; &#60;h1&#62; Connecting to Ms Access using PHP &#60;/h1&#62; &#60;hr&#62; &#60;?php $conn=odbc_connect('acc_php','',''); if (!$conn) { exit("Connection Failed: " [&#8230;]</p>
<p>The post <a href="https://mitindia.in/php-database-connection/">PHP Database connection</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><span style="color: #000080;"><strong>Database connections using PHP and MS Access</strong></span></div>
<div><strong><span style="color: #993300;">1. Display list of records from MS Access  database to PHP web page. (for this example you need to create a DSN from control panel, to create DSN <a href="http://www.mitindia.in/2016/07/09/data-source-naming-dsn/">click here</a>)</span></strong></div>
<div><img fetchpriority="high" decoding="async" class="alignnone" src="https://shivkblog.files.wordpress.com/2015/06/accdb.png" alt="accdb" width="240" height="227" /></div>
<div>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;h1&gt; Connecting to Ms Access using PHP &lt;/h1&gt;
&lt;hr&gt;
&lt;?php
$conn=odbc_connect('acc_php','','');
if (!$conn)
{
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM Cust";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{
exit("Error in SQL");
}
echo "&lt;table border=1&gt;&lt;tr&gt;";
echo "&lt;th&gt;Customer Code&lt;/th&gt;";
echo "&lt;th&gt;Customer Name&lt;/th&gt;";
echo "&lt;th&gt;Address&lt;/th&gt;&lt;/tr&gt;";
while (odbc_fetch_row($rs))
{
$c_code=odbc_result($rs,"ccode");
$c_name=odbc_result($rs,"cname");
$c_addr=odbc_result($rs,"caddr");
echo "&lt;tr&gt;&lt;td&gt;$c_code&lt;/td&gt;";
echo "&lt;td&gt;$c_name&lt;/td&gt;";
echo "&lt;td&gt;$c_addr&lt;/td&gt;&lt;/tr&gt;";
}
odbc_close($conn);
echo "&lt;/table&gt;";
?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<div><strong><span style="color: #993300;">2. PHP and MySQL Database connection</span></strong></div>
<div>
<pre>&lt;?php
$con=mysql_connect("localhost","root", "");
if(!$con)
{
die('could not connect'. mysql_error());
}
mysql_select_db("mars_db",$con);
$result=mysql_query("select * from emp");
echo "&lt;h1&gt; Database connection...................&lt;/h1&gt;";
echo"&lt;table border=1&gt;";
echo"&lt;tr&gt;&lt;th&gt;Employee Number&lt;/th&gt;&lt;th&gt;EmpName&lt;/th&gt; &lt;th&gt;Address &lt;/th&gt; &lt;th&gt;Phone &lt;/th&gt; &lt;th&gt;Salary &lt;/th&gt;";
while ($row=mysql_fetch_array($result))
{
echo"&lt;tr&gt;";
echo "&lt;td&gt;".$row['empno']."&lt;/td&gt;"."&lt;td&gt;".$row['ename']."&lt;/td&gt;" ."&lt;td&gt;".$row['addrs']."&lt;/td&gt;" ."&lt;td&gt;".$row['phone']."&lt;/td&gt;" ."&lt;td&gt;".$row['salary']."&lt;/td&gt;";
echo "&lt;/tr&gt;";
}
echo"&lt;/table&gt;";
mysql_close($con);
?&gt;</pre>
</div>
<div><strong>3. Searching records using PHP MYSQL </strong></div>
<div></div>
<div>
<pre>&lt;?php
$searchTerm = trim($_GET['keyname']);
if($searchTerm == "")
{
echo "Enter code you are searching";
exit();
}
$host = "localhost";
$db = "mars_db";
$user = "root";
$pwd = "";
$link = mysqli_connect($host, $user, $pwd, $db);
$query = "SELECT * FROM emp_db WHERE empno LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
if(mysqli_num_rows($results) &gt;= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "Employee Number: " . $row['ecode'] . "&lt;br /&gt;";
$output .= "Name: " . $row['ename'] . "&lt;br&gt;";
$output .= "Address: " . $row['sal'] . "&lt;br&gt;";
}
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?&gt;</pre>
</div>
<div>
<div><span style="color: #993300;"><strong>4. Inserting records from html page through php to mysql database.</strong></span></div>
<p>a) First create following html file</p>
</div>
<div><img decoding="async" src="https://shivkblog.files.wordpress.com/2015/06/dbmysql.png" alt="dbmysql" /></div>
<div>
<pre>&lt;html&gt;
&lt;body&gt;
&lt;h1&gt; Inserting Records - PHP MySQL &lt;/h1&gt;
&lt;form action="process5.php" method="POST"&gt;
Name: &lt;input type="text" name="name" /&gt;&lt;br /&gt;
DOB : &lt;input type="text" name="dob" /&gt;&lt;br /&gt;
Gender : &lt;select name="gender"&gt;
&lt;option value="M"&gt;Male&lt;/option&gt;
&lt;option value="F"&gt;Female&lt;/option&gt;
&lt;/select&gt;&lt;br /&gt;
Country : &lt;select name="country"&gt;
&lt;option value="USA"&gt;United States of America&lt;/option&gt;
&lt;option value="Australia"&gt;Australia&lt;/option&gt;
&lt;option value="Canada"&gt;Canada&lt;/option&gt;
&lt;option value="India"&gt;India&lt;/option&gt;
&lt;/select&gt;&lt;br /&gt;
&lt;input type="submit" value="Submit Info" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<div>b) Now create a php file called &#8220;process5.php&#8221; with following code.</div>
<div></div>
<div>
<pre>&lt;?php
$nm=$_POST['name'];
$db=$_POST['dob'];
$gn=$_POST['gender'];
$cnt=$_POST['country'];
$host="localhost";
$username="root";
$password="";
$dbname="mars_db";
$con=mysql_connect("$host","$username","$password");
mysql_select_db("$dbname",$con);
mysql_query("INSERT INTO dts (ename, dob, gen, cntry) VALUES ('$nm','$db','$gn', '$cnt')");
echo "&lt;h1&gt; One record added &lt;/h1&gt;";
mysql_close($con);
echo "&lt;img src='MI LOGO.png'&gt;";
?&gt;</pre>
</div>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fphp-database-connection%2F&amp;linkname=PHP%20Database%20connection" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fphp-database-connection%2F&amp;linkname=PHP%20Database%20connection" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fphp-database-connection%2F&#038;title=PHP%20Database%20connection" data-a2a-url="https://mitindia.in/php-database-connection/" data-a2a-title="PHP Database connection"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/php-database-connection/">PHP Database connection</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
