Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Monday, May 28, 2012

Apache, PHP, MySql for development purposes in Windows

No comments:

Important: The Following is for development machine only.

Apache - httpd-2.2.22-win32-x86-no_ssl.msi Link: http://httpd.apache.org/download.cgi
PHP - php-5.2.17-Win32-VC6-x86.zip Link: http://windows.php.net/download/
MySql - mysql-installer-5.5.24.0.msi Link: http://www.mysql.com/downloads/installer/

Slected: Apache module + PHP V6-Thread Safe

(I) Configuring Apache

1. Install Apache

2. add the following in [Apache]\conf\httpd.conf
LoadModule php5_module "C:/php/php5apache2_2.dll"
<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>
<IfModule mime_module>
AddType application/x-httpd-php .php
</IfModule>
3. Restart Apache

Your webroot will be at [Apache]\htdocs. You can change this path by editing the lines mentioned below in [Apache]\conf\httpd.conf
Eg:
DocumentRoot "C:/.../Apache Software Foundation/Apache2.2/htdocs" to
DocumentRoot "D:/ htdocs"
and
<Directory "C:/.../Apache Software Foundation/Apache2./htdocs"> to
<Directory "D:/htdocs">

(II) Configuring PHP

1. Extacted PHP zip to 'C:\php'

2. copy and rename [php]\php.ini-dist to [php]\php.ini

3. add the following in php.ini
extension=php_mysql.dll
extension_dir = "c:\php\ext"
4. copy [php]\libmysql.dll and [php]\php.ini to [Apache]\bin

5. Restart Apache

(III) Configuring MySql

Install as per your requirement.

Thursday, July 28, 2011

PHP and MS SQL Server connection in IIS 7

No comments:

<?php
$connectionInfo = array("UID" => "sa", "PWD" => "asdf123*", "Database"=>"testdb");
$serverName = ".\SQLEXPRESS";
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )
{
     echo "Connection established...<br />";
}
else
{
     echo "Connection could not be established.\n";
     die( print_r( sqlsrv_errors(), true));
}

//Lets do some sample sql select.

// Send a select query to MSSQL
$stmt = sqlsrv_query($conn,'SELECT * FROM users');
if( $stmt === false)
{
     echo "Error in query preparation/execution.\n";
     die( print_r( sqlsrv_errors(), true));
}
// Check if there were any records
if (sqlsrv_has_rows($stmt)==false) {
    echo 'No records found';
} else {
?>
<table width="100%" border="2px">
<?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { ?>
<tr>
    <td><?php echo $row['name']; ?></td>
    <td><?php echo $row['designation']; ?></td>
</tr>
<?php } ?>
</table>
<br /> <?php
}
// Free the query result
sqlsrv_free_stmt($stmt);

/* Close the connection. */
sqlsrv_close($conn);

phpinfo();
?>

Sunday, December 26, 2010

jquery post sample

3 comments:
Database table:

CREATE TABLE `comments` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 50 ) NOT NULL ,
`comment` VARCHAR( 255 ) NOT NULL ,
`time` INT( 9 ) NOT NULL
)

process.php

<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "newdb";

$name=$_POST['name'];
$comment=$_POST['comment'];

$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error);
$select_db=mysql_select_db($dbname) or die("cannot find database!");

$sql= "INSERT INTO comments (`name`,`comment`,`time`) values ('$name','$comment',".time().")";

mysql_query($sql) or die("insert failed.");

echo true;

?>

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<title>Jquery - samples</title>


<style>
#response
{
border: 5px solid #99CCFF;
background: #00CCFF;
}
</style>


<script type="text/javascript">


$(document).ready(function()
{
$("#response").hide();


$("#addComment").click(function()
{
if( $("#name").val()!='' && $("#comment").val()!='')
{
$.post(
"process.php",
{
name:$("#name").val(),
comment:$("#comment").val()
},
function(response)
{
if(response == true )
{
$("#response").fadeIn('normal');
$("#response").html('Comment Added!');
$("#name").val('');
$("#comment").val('');
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Insertion failed!');
}
}
);
}
else
{
$("#response").fadeIn('normal');
$("#response").html('Please enter your name and comment!');
}
return false;
});


$("#response").click(function()
{
$("#response").fadeOut('slow');
});

$("#resetall").click(function()
{
  $("#name").val('');
  $("#comment").val('');
$("#response").hide();
});
});


</script>
</head>


<body>
<form id="commentform">
<table width="100%" border="1">
  <tr>
    <th scope="row">Name</th>
    <td><input name="name" type="text" id="name" size="50"/></td>
  </tr>
  <tr>
    <th scope="row">Comment</th>
    <td><textarea id="comment" name="Comment" cols="50" rows="3" ></textarea></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><input name="submit" type="submit" id="addComment" value="Add"/>
      <input name="button" type="button" id="resetall" value="Reset"/></td>
  </tr>
</table>
</form>
<div id="response"></div>
</body>
</html>

Sunday, March 14, 2010

Reading and Updating a mysql table using php

No comments:
<?php
//Establishing connection with database and including functionalities
define('DB_HOST','localhost');
define('DB_NAME','mydb');
define('DB_USER','root');
define('DB_PASS','');
$con=@mysql_connect(DB_HOST,DB_USER,DB_PASS);
$bd=@mysql_select_db(DB_NAME) or die ("Cannot connect to the database".mysql_error());
?>


<?php

if (isset($_POST['Submit']))
{

  $title=$_REQUEST['txtitle'];
$desc=$_REQUEST['txtdesc'];
{
$sql1=@mysql_query("Update `about` Set `title` = '$title' , `desc` = '$desc' where id='1'");
if(!$sql1)
{
@mysql_query("ROLLBACK");
}
}
}

$sql2=@mysql_query("Select * from `about` where id='1'");
if(mysql_num_rows($sql2)>0)
{
$rs=@mysql_fetch_object($sql2);
}

?>

<html>
<body>
<form action="one.php" method="post">
<table width="100%" border="1">
  <tr>
    <th scope="row">Title</th>
    <td><input name="txtitle" type="text" id="textfield" value="<?php echo $rs->title;?>" /></td>
  </tr>
  <tr>
    <th scope="row">Desc</th>
    <td><textarea name="txtdesc" id="txtdesc" cols="45" rows="5"><?php echo $rs->desc;?></textarea></td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td><input type="submit" name="Submit" id="button" value="Send" /></td>
  </tr>
</table>
</form>
</body>
</html>

Saturday, February 13, 2010