Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I access a sql database on my web page?

I've worked with WAMP to create, edit, export and import data in a table, but I want to do the same thing with a table on a web page. I created a small sample table and uploaded it to my web page. Now, how do I access it? Is it just a html page with some php script?

Update:

Here's a sample php script from the page suggested. Where is the name of the table?

<?php

// This could be supplied by a user, for example

$firstname = 'fred';

$lastname = 'fox';

// Formulate Query

// This is the best way to perform a SQL query

// For more examples, see mysql_real_escape_string()

$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",

mysql_real_escape_string($firstname),

mysql_real_escape_string($lastname));

// Perform Query

$result = mysql_query($query);

// Check result

// This shows the actual query sent to MySQL, and the error. Useful for debugging.

if (!$result) {

$message = 'Invalid query: ' . mysql_error() . "\n";

$message .= 'Whole query: ' . $query;

die($message);

}

// Use result

// Attempting to print $result won't allow access to information in the resource

// One of the mysql result functions must be used

// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), e

3 Answers

Relevance
  • arbpen
    Lv 5
    1 decade ago
    Favorite Answer

    The name of the table in your query is Friends. I do not see a connection string to the db. Make sure you are opening a connection to the db before running the query. Here's a connection string:

    <?php

    $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

    if (!$link) {

    die('Could not connect: ' . mysql_error());

    }

    echo 'Connected successfully';

    mysql_close($link);

    ?>

  • 5 years ago

    I agree that Microsoft Access is quite happy to serve as a database for smaller web sites. It doesn't like many more than about 50 concurrent users and you need to ensure that there are weekly maintanence jobs that repair and compact the database as Access has a habit of consuming space quickly. ASP is the primary scripting language when it comes to using Microsoft Access as a database because it can use both ADODB and ODBC to connect to the database. JSP (Java Server Pages) and PHP can also connect to Microsoft Access using ODBC. Once the ODBC connections are set up you have to use SQL to query and update the database.

  • 1 decade ago

    That's pretty much it; you collect the data from the database into an array, and place the array's data into an HTML table...

    Go to http://www.php.net/mysql_query to see how to retrieve data; there's a lot of examples on those pages.

Still have questions? Get your answers by asking now.