Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:59+00:00 2026-05-27T14:49:59+00:00

I am trying to set up a script that queries a database to populate

  • 0

I am trying to set up a script that queries a database to populate a page. This is my first foray into database querying in PHP, so forgive me if the problem is something really stupid.

The problem I have is that the page does not seem to connect to the database, as the first 2 debug statements are rendered in the browser, but nothing after them is. however, when I run it on the command line using php.exe, it runs properly and displays all required data from the query.

I am running wampserver 2.2 on windows 7 and it does not display in any browser (tested in Chrome, Firefox, and IE9.

My current code is below. I have also tried moving the connection to the head, but that prevents anything, even debug1, from rendering. The die statement is not rendered in any circumstance.

<html>

<body>   
debug1<br /> 

<?php
echo "debug2<br />";
$con = mysql_connect("hostname.of.database","username","password") die('Could not connect: ' . mysql_error());
echo "debug3<br />";

mysql_select_db("dbname",$con);

$result = mysql_query("SELECT * FROM Mail");

while ($row = mysql_fetch_array($result))
  {
  echo $row['Sender'];
  echo "<br />";
  echo $row['Subject'];
  echo "<br />";
  echo $row['Message'];
  echo "<br />";
  echo "<br />";
  }

echo "debug4<br />";

mysql_close($con);
?>
</body>
</html>

EDIT

After moving the die statement to the same line as the connection, I get the following rendered in the page:

Fatal error: Call to undefined function mysql_connect() in C:\wamp\www\test.php on line 10

EDIT

I have added extension=php_mysql.dll to my php.ini file and restarted the servers. I am now getting the following page:

error messages

EDIT

Problem solved. My last problem was that I forgot to replace hostname.of.database with the actual hostname.

For those who read this in the future, the solution is as follows:

  1. don’t close the connection before retrieving the results
  2. ensure that the php_mysql extension is enabled by adding extension=php_mysql.dll to the php.ini file
  3. reboot the server, clear the browser cache and try again.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:50:00+00:00Added an answer on May 27, 2026 at 2:50 pm

    Because you’re closing the connection before fetching results:

    // Don't do this!!!
    //mysql_close($con);
    
    while ($row = mysql_fetch_array($result))
      {
      echo $row['Sender'];
      echo "<br />";
      echo $row['Subject'];
      echo "<br />";
      echo $row['Message'];
      echo "<br />";
      echo "<br />";
      }
    

    Unless you specifically have a need to free some memory or destroy a connection when you intend to create another one, it is usually not necessary to make explicit calls to mysql_close(). It will be called when the script completes execution.

    Update:

    After posting your error message, it would appear that the MySQL extension is not enabled for your WAMP stack. A different php.ini file may be used by the command line than is used by the web server. Locate the correct php.ini by calling phpinfo() and enable the MySQL extension.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to copy a database into a new database, using a PHP script that
I am trying to set up a php script that takes the input from
I'm trying to write a shell script that, when run, will set some environment
I'm trying to set data in long-term storage in a GreaseMonkey script, except that
I'm trying to set up a shell script that will start a screen session
I have a Perl script that's trying to set some configured DateTime and DateTime::Duration
I have a TSQL script that is used to set up a database as
I am trying to set up this script for my local bands newsletter. Currently,
I'm trying to set up a script that will search for multiple keywords and
Trying to set up a simple login script in flex 4 with php. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.