开发者

How to get started with sql and php?

I was wondering how to link a SQL database on my PHP code. I am using a database on my local server that I set up and I have already created a database, I tried writing a PHP script with ++notepad, but 开发者_如何转开发when I clicked on the script, it opened the browser and displayed a blank page. What am I doing wrong? I created my databases using phpMyAdmin.


You need to be running a web server locally which supports PHP (like Apache). It it the web server which does the PHP processing. At the same time you will have to run a MySQL (or any other) database engine too, so your PHP code can connect and query it. (I'm assuming you've already installed PHP.)

I would recommend you install XAMPP which includes Apache, PHP, MySQL and a bunch of other stuff. It one of "Apache friends". Once you install XAMPP you would have a folder htdocs in the xampp folder. Create a folder for you project myproject and place your PHP script script.php in there. Now if MySQL and Apache are running following should behave as you expect.

http://127.0.0.1/myproject/script.php

For the tutorial, to begin with you can use W3Schools. Brief and to the point. They have both a PHP tutorial and a SQL tutorial.


This is a very good book to start with: PHP and MySQL Web Development Luke Welling and Laura Thomson

You have to play with php/sql code practically. Only reading cant help!

go for w3shools as mentioned above :)

start with simple code and then go to the complexity. all the best.. :)


There are multiple ways on how to do that.

One of the most modern ways to do that, is to use PDO to connect to the DB with PHP.


To run PHP on your PC(which i assume is your workstation), you need the supporting software for it, for php to run you need the PHP software installed, and likewise if you want to run the server software you need apache, however you can go for a single install package which will install almost everything for you to run your php script, download and install the wamp.

to install wamp which stands for (windows, apache, mysql, PHP) if you are running windows, and lamp for linux or mamp for mac, all of which are free softwares, you can download wamp from the following link. http://www.wampserver.com/en/download.php that is the first step which you need to do.

step 2: once wamp is installed the default directory of installation is C:/wamp (i reccomend do not change the location of the installation), you need to start the wamp server by just opening or double clicking the software which you just installed.

step3: navigate to the default directory where you should be storing your PHP files and that is C:/wamp/www note that you should be keeping all your PHP files here apart from this location if you store it anywhere else it wont simply run at all, and that it should and must have the .php extension.

step4: create or save the php files in this location(c:/wamp/www) i for example will assume you have created a file test.php in the www folder. now to access this file open your web browser and type http://localhost/test.php there you go, you will have the access to your PHP file (Note: PHP files cannot be run by simply double clicking the file, you have to follow this procedure in order to run the PHP files)

step5: open the test.php in any of your text editor like notepad, or i recommend use an IDE (Netbeans is free and worth a try), and write your code in the following format.

<?php

your PHP code should go here.

?>

when i started writing the code i started by following a nice tutorial which i found in zend.com, it has one of the best examples, and moreover the tutorial is meant for the beginners. hope this helps you..

http://devzone.zend.com/tag/PHP101

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜