Click to See Complete Forum and Search --> : Dreamweaver: Linking PHP to MySQL


kent_will
01-18-2006, 06:00 AM
Ok, have experience in HTML, design, Java, JavaScript and am no stranger to modern programming languages or SQL. BUT have not ever even seen PHP, or ASP.

I'm teaching myself PHP and MySQL.

Have tried to download PHP, Apache and MySQL to no avail. So decided to try Dreamweaver. Connected to my Web Server successfully but have absolutly no idea how to link to a MySQL database. I can write simple PHP but where do I hold my database in the file structure, have created databases using my Hosting control panel but cant find where they are or edit them.

What I need to know is:
1) need a program to write MySQL in and dreamweaver cant (could I use a text file though and rename it?

2) How do i get the PHP code to find and use the database.

I'm a complete newby to this. Ive written basic SQL at uni but just dont have the software now. and cant remember. think we used PostgreSQL anyway. My knowledge is so patchy, can anyone help??

Would be much appreciated.

Will

knowj
01-18-2006, 07:59 AM
you can use this code

<?php
$dblogin = "LOGIN NAME";
$dbpassword = "PASSWORD";
$dbname = "DATABASE NAME";
$dbhost = "localhost"; //usually localhost the sql servers ip address
$link = mysql_connect($dbhost, $dblogin, $dbpassword)
or die('Could not connect: ' . mysql_error());
mysql_select_db($dbname) or die('Could not select database');
?>


or in dreamweaver change your pages filetype to .php then click on the applications tab on the right side menus. click add server (you may need to fill in the details for a testing server etc..)

i personally perfer to write the code/script myself as dreamweaver doesnt do the best job of it.

dreamweaver will also write the php for you for many basic serverside tasks using the tabs on this menu

kent_will
01-18-2006, 11:00 AM
Thanx thats cleard it up, but if I put that in my code, wont people be able to find my password/username when they view code?

knowj
01-18-2006, 11:39 AM
no as it is processed serverside so it never reaches the persons browser.


also its best to have it in a file named whatever you want in a folder which i usually name connections and use the code below to include it into each files you require a database connection

<?php require_once "connections/filename.php"; ?>

kent_will
01-26-2006, 08:32 AM
That makes it harder for them to get my Username and password, but whats to stop them looking at the code in the page they are viewing, seeing the path (connections/filename.php) then they download that file i.e. set up a link and save target as. Once they have the php file they can get my username and password by viewing it at their leisure?

ShrineDesigns
01-26-2006, 01:28 PM
don't use dreamweaver's application panel it is a joke, esp. if you are building web applications

knowj
01-27-2006, 07:44 AM
they wont see any of the code.


no php code is displayed in the pages source as it is all processed serverside.

user makes request for page > php is processed on server > html is processed by the actions of the php script > html is displayed to the client

basically they wont be able to see any php you write and the wont be able to get your password etc... without some how hacking/cracking your script which i very much doupt will happen.

also in the connections folder put a index.html file which is blank/routes the person back to the home page just as an extra precaution. you can also setup other security options on the folder via your host.

i can using cpanel on my webhost