I am just getting started in php and sql, I was wonder if how to link sql database to on my php code, I know how to create databases and i know a little about php, but i don't know how to link the databases to my 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 scrip it open the browser and displayed a blank page. what am i doing wrong? o and I created my databases using myphpadmin.
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.. :)
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..