Testing PHP/MySql without a server?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Orsen
Forum Newbie
Posts: 11
Joined: Thu Sep 23, 2010 7:51 am

Testing PHP/MySql without a server?

Post by Orsen »

Hello,

I recently got dreamweaver cs5 and was wondering if its possible to test php/mysql within the program without having a server?

If this is not possible, where is the cheapest place for servers? I won't be using much space just practicing.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Testing PHP/MySql without a server?

Post by greyhoundcode »

If you mean that you don't want to purchase hosting then perhaps you should look at a package like Xampp which, simply put, will allow you to test out code and run web apps on your local machine.

Other similar packages also exist, depending on your personal preference and what sort of OS you are running.

Wamp
Mamp
EasyPHP

You could also get hold of and install individual parts of the stack separately.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Testing PHP/MySql without a server?

Post by McInfo »

PHP and MySQL servers are necessary; however, expense is not. Web programmers typically install an HTTP server (Apache, IIS, etc.) on a local machine along with a database server (MySQL, etc.). Together, that locally-installed software makes up the development environment. When the developed application is ready for public use, it is uploaded to a production environment.

It is possible to create a development environment with no-cost software. As greyhoundcode mentioned, the quickest and easiest way to set up a server is to install a bundle like XAMPP. If the HTTP server lives on the same machine as your browser, it is known to your browser as "http://localhost/" or "http://127.0.0.1/".
Orsen
Forum Newbie
Posts: 11
Joined: Thu Sep 23, 2010 7:51 am

Re: Testing PHP/MySql without a server?

Post by Orsen »

I've installed Apache 2.2 and my server is running fine.

Only problem is that some of the php commands do not work, echo for example is fine but getting information from a text file does not want to work.. Im trying to create a listing system that basically has all my possessions and once someone borrows one of my items, I can change it to "Lent out" while giving it a time limit too, so in 2 weeks time I'll either email them or send an SMS text message.

Thanks for the recommendations.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Testing PHP/MySql without a server?

Post by Jonah Bron »

What do you mean "does not want to work"? Do you get an error? Do you have errors enabled? If you don't, you should. A development environment should always have errors enabled.

http://nucleussystems.com/blog/enable-error-reporting
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Testing PHP/MySql without a server?

Post by McInfo »

If you want help with a particular script, please post the code. Also state where the files are located.

You may be better off using a database instead of a text file.
Orsen
Forum Newbie
Posts: 11
Joined: Thu Sep 23, 2010 7:51 am

Re: Testing PHP/MySql without a server?

Post by Orsen »

Code: Select all

<?
$data=file_get_contents('list.txt'); 
$dat=explode("\r\n",$data); 
echo '<table border=1 cellpadding=3 cellspacing=0>';
foreach ($dat AS $val) { 
echo '<tr><td>'.$val.'</td></tr>'; 
}echo '</table>';
?>
The file is located in the same folder as the php file.

When I load the php file all it shows is

Code: Select all

}echo '</table>';?>
No error messages : / They are enabled I checked.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Testing PHP/MySql without a server?

Post by Jonah Bron »

That means that PHP isn't being executed. Try using full <?php ?> tags instead of the short <? ?> tags. That's a best practice anyway.
Orsen
Forum Newbie
Posts: 11
Joined: Thu Sep 23, 2010 7:51 am

Re: Testing PHP/MySql without a server?

Post by Orsen »

I tried it, but to no such luck.

Its definitely not recognising PHP anymore, it was working fine a few weeks back but it's packed up and I have no idea how to fix it... : /

Definitely need a server thats reliable and not installed by myself :DD
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Testing PHP/MySql without a server?

Post by social_experiment »

How are you running the file i.e http://localhost/your_file.php ? Paste the following into a file name file.php then execute it (and report your results :) )
Hth

Code: Select all

<?php phpinfo(); ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply