Skip to main content
Participant
May 31, 2017
Answered

Question about using information from database - Dreamweaver CC

  • May 31, 2017
  • 3 replies
  • 613 views

I am looking for a basic solution to populating database information into a website. I have attempted to follow tutorials on the Adobe website and came to a dead end when the databases panel could not be found. The reality is I am a complete beginner and not even sure what type of tutorials I should be looking for. Here are the basics of what I would like to do.

I have a database that only has 4 or 5 columns, around 4,000 rows. A few columns specify a category, one column shows the text I would like to appear on the site, and the other column contains a link to a webpage I would like visitors to access. I initially planned on creating 60 web pages (based on column category), and manually adding the text and hyperlink to each page. I am thinking it may be easier if I created one page that would just populate the data depending on what the visitor selected as filters. I have no need for visitors to interact with the database other than just retrieving the information. The data I have in the database is not likely to change on a regular basis.

I am open to learning whatever is necessary to accomplish this but have had a dead end with the tutorials on PHP and connecting a SQL database. Any suggestions?

This topic has been closed for replies.
Correct answer osgood_

dai23each  wrote

I went through the videos and could not get the database to connect (video 3). The tutorial was not done using Dreamweaver as far as I could tell.

I am looking for a tutorial to connect a database to Dreamweaver. This seems like such a simple request but the more I explore what is available on the web the more confusing it gets.

Any other suggestions?

Ok I realise this can be all a bit overwhelming to start with so try something reasonably simple.

You say you have a database (is that on your local machine and is it an sql database)?

If yes then try the code below. Replace the detalis in the database connection string (marked in red) with your own details (server name (usually 'localhost' if the database is local on your machine), 'username for the database', 'password for the database' and the 'database name':

Replace database_table_name (marked in red) for the name of your database table name.

Replace 'database_column_name' (marked in red) for the name of one of your database column names.

If all is successful you should get a list printed to the page of all the data that is in the database column name.

<?php

// connect to database local

$conn = new mysqli('localhost' , 'username' , 'password' , 'database_name');

// get data to display on page

$data = $conn->query("SELECT * FROM database_table_name") or die($conn->error);

$numRows = $data->num_rows;

?>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" />

<title>Database Connect</title>

</head>

<body>

<?php

// Number of results found in database

echo $numRows; ?>

<?php

// Print results to the page

while($row = $data->fetch_assoc()) { ?>

<p><?php echo $row['database_column_name']; ?></p>

<?php } ?>

</body>

</html>

3 replies

Nancy OShea
Community Expert
Community Expert
June 1, 2017
  1. Have you installed & defined a local testing server yet?
  2. Is your local testing server on and are all PHP and Apache processes running?
  3. Which version of PHP is installed on your server?
  4. Which method are you using to connect to your database -- MySQLi (improved) or PDO?

The deprecated server behaviors in DW CS6 were removed for a reason.  The connection code generated by those panels is obsolete.  It won't work on modern servers running PHP 7 or higher.   Do not use the deprecated server behavior panels in DW.  You will need another method either MySQLi or PDO.

Nancy

Nancy O'Shea— Product User & Community Expert
dai23eachAuthor
Participant
June 3, 2017

1. yes

2. Yes

3. 7.1.1

4. I have no idea what method I used to connect. I used the code supplied by osgood and I am assuming it is Mysqli.

Nancy OShea
Community Expert
Community Expert
June 3, 2017

That tutorial was written for CS5.  While the 1st part about installing and setting up a local testing server is still relevant, the 2nd half related to using Server Behavior Panels is not.  The code created by those panels won't work with PHP 7.  It's outdated code and should never be used.

Nancy

Nancy O'Shea— Product User & Community Expert
tmyusuf74
Inspiring
May 31, 2017

<a href="details.php?month=January">January</a>

Legend
May 31, 2017

Have a look at this set of youtube videos below.

PHP and MySQL with MySQLi: Introduction (Part 1/9) - YouTube

Once you understand the basics of fetching data from a database you can then fetch it based on some specific critrea.

As a simplified example - below shows links which pass some criteria to a 'details.php' page after the ?.

<a href="details.php?month=January">January</a>

<a href="details.php?month=February">February</a>

<a href="details.php?month=March">March</a>

In the details.php get the name of the month passed via the link:

$month = $_GET['month'];

Then you can query the database and return results based on the month name:

SELECT * FROM months WHERE month = $month

'months' is the table name in your database - 'month' is the column and $month is either January/February or March, depending on what link is selected.

Go through the videos as things will start to fall into place easier by watching something.

dai23eachAuthor
Participant
June 1, 2017

I went through the videos and could not get the database to connect (video 3). The tutorial was not done using Dreamweaver as far as I could tell.

I am looking for a tutorial to connect a database to Dreamweaver. This seems like such a simple request but the more I explore what is available on the web the more confusing it gets.

Any other suggestions?

osgood_Correct answer
Legend
June 1, 2017

dai23each  wrote

I went through the videos and could not get the database to connect (video 3). The tutorial was not done using Dreamweaver as far as I could tell.

I am looking for a tutorial to connect a database to Dreamweaver. This seems like such a simple request but the more I explore what is available on the web the more confusing it gets.

Any other suggestions?

Ok I realise this can be all a bit overwhelming to start with so try something reasonably simple.

You say you have a database (is that on your local machine and is it an sql database)?

If yes then try the code below. Replace the detalis in the database connection string (marked in red) with your own details (server name (usually 'localhost' if the database is local on your machine), 'username for the database', 'password for the database' and the 'database name':

Replace database_table_name (marked in red) for the name of your database table name.

Replace 'database_column_name' (marked in red) for the name of one of your database column names.

If all is successful you should get a list printed to the page of all the data that is in the database column name.

<?php

// connect to database local

$conn = new mysqli('localhost' , 'username' , 'password' , 'database_name');

// get data to display on page

$data = $conn->query("SELECT * FROM database_table_name") or die($conn->error);

$numRows = $data->num_rows;

?>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" />

<title>Database Connect</title>

</head>

<body>

<?php

// Number of results found in database

echo $numRows; ?>

<?php

// Print results to the page

while($row = $data->fetch_assoc()) { ?>

<p><?php echo $row['database_column_name']; ?></p>

<?php } ?>

</body>

</html>