English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm new to php and don't know where I'm putting my PHP code. I know is to put it into a text file and save it as .php and then put on my server...duh. But what if I want to connect to a mysql database and have the information print on the screen? Do I use command promp on my computer or is there a specific program? Please keep your answer simple and give examples.

2007-11-14 03:23:11 · 4 answers · asked by chrispmv 2 in Computers & Internet Programming & Design

The first answer is very unhelpful...notice i did not ask for code or script...i asked for WHERE to type it or where to put it. Answer number two is much more helpful. thanks so far.

2007-11-14 03:50:02 · update #1

4 answers

Hi,

To use PHP, you need a few things:

1) Install a web server (Microsoft IIS or Apache)
2) Install PHP (see www.php.net)
3) Install MySQL (see www.mysql.com)

PHP is interpreted language (e.g. not compiled) and can be edited with any notepad-like application. However, if you want to develop applications, I recommend a specialized program such as Adobe Dreamweaver.

You can run PHP on a command prompt, without any web server, if you want to simply play around with it. Once installed, you'll have a "php.exe" file in the installation folder. You can run a command such as:

php.exe -f my_test_php_code.txt

In my_test_php_code.txt, you could have something like:

print "hello world!";
?>

That would be a great start.

Afterwards, I recommend that you learn the rest of PHP (including MySQL connectivity) at: www.php.net/manual/en

Good luck!

2007-11-14 03:37:50 · answer #1 · answered by Bernz 6 · 0 0

For a quick start I would tell you to read these! PHP runs on a web server. MySql also needs a server. You will have to have a server on your LOCAL machine to "run them". You can instal PHP and MySql as well as Apache on Windows Linux or nearly any other computer. BUT for either to work a server has to process the output of the php code.

http://www.freewebmasterhelp.com/tutorials/phpmysql
http://www.php-mysql-tutorial.com/

A great starting book is
Teach Yourself PHP MySql and Apache in 24 Hours by Meloni. It even has a CD to install all of them and let you run locally.

http://www.amazon.com/Teach-Yourself-MySQL-Apache-Hours/dp/067232489X

You can also download all the server for Windows
http://www.wampserver.com/en/
or for Linux
Just Install Ubuntu SERVER all these are included! Can even run from the CD.
http://ubuntu.com

Hope that helps.

2007-11-14 05:56:28 · answer #2 · answered by Tracy L 7 · 0 0

connectdb();
$result = mysql_query("SELECT field FROM table");
while ($row = mysql_fetch_array($result))
{
$page .= $row['field'] . "
";
}

echo $page;

function connectdb()
{
mysql_connect("localhost", "username", "password") or die ("Could not connect to database");
mysql_select_db("databasename") or die ("Could not select database");
}

?>


Does that help?

Edit: Where to put it - Anywhere in the file. AS long as your webserver is set up to parse .php files you can use php anywhere in your php file. It just needs to be within the "" tags.

So you could have the file mostly html with pieces of php inserted, or the whole file could be contained within those tags.

2007-11-14 03:32:16 · answer #3 · answered by Andrew 3 · 0 0

notepad ++ is loose and you are able to p.c. the language to code in (it gadgets the margins and stuff for each language, click on language and choose what you're doing and then code away)

2016-10-16 12:14:04 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers