Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a site in ASP

Status
Not open for further replies.

gsc123

Programmer
Jan 24, 2008
197
How easy is it to convert to PHP
 
Well that would depend, how complex a site is it? How large is it? how much actual ASP code (not HTML or Javascript, but actual ASP) does it use.

If it uses regular functions and properties probnably not to difficult. If it uses many ASP proprietary functions that may not have a PHP equivalent likely, much harder.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Well its meanly SQL driven - but yes, many functions..

can you convert this to PHP so I can see where your coming from?

Function processSQLruns(valType)
select case valType
case 1
sql = "SELECT TOP 1 bidhistory.bidAmount AS price FROM bidhistory WHERE (((bidhistory.idProduct)="&Session("pIdProduct")&") AND ((bidhistory.idCustomerBid) <> "&session("idcustomer")&")) ORDER BY bidhistory.bidAmount DESC "
set rsMaxBid = conntemp.execute(sql)
Response.Write sql
if not rsMaxBid.EOF or not rsMaxBid.BOF then
pPriceMaxBidNotMine = rsMaxBid("price")
processSQLruns = pPriceMaxBidNotMine
else
pPriceMaxBidNotMine = 0
end if
case else
Response.write "do nothing"
end select
End Function
 
Code:
<?php
function processSQLruns($valType){
    switch ($valType):
	    case 1:      
	        $sql = "SELECT TOP 1 bidhistory.bidAmount AS price FROM bidhistory WHERE (((bidhistory.idProduct)="&Session("pIdProduct")&") AND ((bidhistory.idCustomerBid) <> "&session("idcustomer")&")) ORDER BY bidhistory.bidAmount DESC ";
	        //assuming database already connected
			$result = mysql_query($sql);
	        if(!$result):
	        	echo "Error with query: $sql. error was " . mysql_error();
				return false;
	        endif; 
			if (mysql_num_rows($result) == 0 ):
				$pPriceMaxBidNotMine = 0;
			else:
				$rsMaxBid = mysql_fetch_object($result);
		        return $rsMaxBid->price;
				//can also do this with mysql_fetch_assoc and use array notation: $rsMaxBid['price']        
	        endif;
		break;
	    default:
	        echo "do nothing";
	endswitch;    
}
$processSQLruns = processSQLruns($valType);
?>
 
Its a whole new world.. which do you prefer?
 
i'm surprised you say it's a whole new world. i deliberately kept the coding as similar as possible to the vb that you posted.

key differences (apart from some function names) are this:

variables are identified by a $ sign
php is vertical white space agnostic. thus all lines must be expressly terminated with a semicolon.
variable scope is contained like many other language. so you must return a value from a 'subroutine'.

other than the above stylistic differences, the two code snips seem pretty similar to me.

preference: php. but i'm biased as my vb coding days were for discrete desktop apps rather than websites. i like the portability of php and the fact that the manual is so much better documented than anything i have come across in other languages.
 
Also a lot depends on what your trying to do with the site. In technologies like ASP, JSP (Java Server Pages) and PHP there tends to be a large interpretation overhead. JSP is a litte better in that is compiles into a java class which then gets compiled to support the page, this recuces a lot of run-time overhead.
In a smallish site you get away with but once you start scaling up with complexity you start to hit scale issues. I can't confirm this this but I'm told the Zend framework siffers as every page request needs to include 10+ files before it starts. That's quite an overhead in terms of opening the files and parsing them before they actualy do any real work. However if this too 1 second and the process took 30 seconds to run it would matter little.
I'm sure that there are many hugh sites that run using PHP but they will be carefully written and run on hardware appriopriate to the performance required.
I like asp.net for a variety of reasons such as it is compiled, you get a lot of goodies out of the box to help you along, it's very fast, I can get c# or vb.net developers to code up quite quickly and cheaply, it's got god seperation between presentation and code, it's supported by Visual Studio (which is awesome even in the free version) and it's supported by the largest software house in the world (which may or may not be a good thing!). However there is a learning curve with the .NET environment which for a non trivial project can be siggnifficant.
PHP is of course more open, you can even change it yourself and it runs on every signifficant platform not just windows.
If you want a smallish site and are prepaired to put up with the the one-size-fits-all (by which I mean intermingling of presentation and business logic) of approach of PHP (unless you want to run an MVC configuration) you will be well served by PHP.
 
just some fyi's,

i think that there is no need to intermingle presentation and business layers. the fact that you can use the same language for both does not make them forcibly intermingled. this is predominantly a design choice.

php code can be 'compiled', albeit not in the same way as c++ etc. zend optimizer and others do this, i believe, by cacheing compiled scripts. i've not looked into them though: hardware costs are so low these days that it always seems easier to add an extra box to the mix.
 
agree but when you see counltess examples on this forum of a query issued then the loop directed by the result set and loads of echos with html and php in the same such as;
<td></b><?php echo $rs->fred;?></td> - too many <'s !
it does get brittle and confusing very quickly.
Yes it is a design choice but as I said if you go the zend framework you run into other issues. Perhaps a simpler MVC pattern is an alternative.
Zend encoder is a good option and if you really need to you can write an extnetion that may contain legacy code or just written in C where the complexity/performance warrents it.
There's been loads of talk here about scale out i.e. adding another box but that again brings issues such as session managment, load balancing etc.
Never an easy thing building web sites, it's a shame that dummys guides and wrox books dont reflect that a bit more !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top