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 6192733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:59:40+00:00 2026-05-24T02:59:40+00:00

trying to get my first little PHP script to connect to a local mySql

  • 0

trying to get my first little PHP script to connect to a local mySql database and am having some trouble. I used a cookie cutter script from the net to get going and am having some issues. In order to debug so far all I’ve done is place echo statements before and after the line where I connect to the database and noticed that there is a problem with the connection statement.

Here is the code i’m using, taken verbatim from W3Schools:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

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

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

mysql_close($con);
?>

Naturally I changed the passwords and all that and verified that I can connect to the database from the mysql command line tool.

Any tips would be greatly appreciated.

Here is the log located at: /var/log/mysql/error.log

Version: '5.1.54-1ubuntu4'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)
110727  1:38:22 [Note] /usr/sbin/mysqld: Normal shutdown

110727  1:38:22 [Note] Event Scheduler: Purging the queue. 0 events
110727  1:38:23  InnoDB: Starting shutdown...
110727  1:38:25  InnoDB: Shutdown completed; log sequence number 0 15895194
110727  1:38:25 [Note] /usr/sbin/mysqld: Shutdown complete

110727 14:08:56 [Note] Plugin 'FEDERATED' is disabled.
110727 14:08:56  InnoDB: Initializing buffer pool, size = 8.0M
110727 14:08:56  InnoDB: Completed initialization of buffer pool
110727 14:08:57  InnoDB: Started; log sequence number 0 15895194
110727 14:08:58 [Note] Event Scheduler: Loaded 0 events
110727 14:08:58 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.1.54-1ubuntu4'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

SO I learn’t how to get some meaningful debug info from PHP thanks to @nix, add the following lines to the top of the php file:

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
  • 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-24T02:59:41+00:00Added an answer on May 24, 2026 at 2:59 am

    So it turns out that the php5-mysql library was not installed.

    sudo apt-get install php5-mysql

    that’s it!

    Thanks to @nix for taking care of this one.

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

Sidebar

Related Questions

I've been trying to get this little project I'm doing finished, but for some
I am trying to get PhysX working using Ubuntu. First, I downloaded the SDK
Im trying to get into some basic JavaFX game development and I'm getting confused
This is my first question :). Im writing a little twitter app in PHP
I am trying to build a website with mysql and php. This is the
I'm learning PHP and MySQL to get a hang of server-side scripting and for
First of all a little background of my problem, i'm trying to identify how
I've got a little problem. Well, let me first state what I'm trying to
I'm trying to programmatically retrieve the comment for a MySQL table. The first method
I'm trying get values from a GridView using the following code: foreach (GridViewRow row

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.