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

  • Home
  • SEARCH
  • 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 586687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:07:59+00:00 2026-05-13T15:07:59+00:00

I am trying to connect my PHP code to MySQL safely with the following

  • 0

I am trying to connect my PHP code to MySQL safely with the following code:

<html>
    <?php
        $con = mysql_connect("localhost:3306","root","password");
        if(!$con)
        {
            die('Could not connect: ' . mysql_error());
        }
        else
        {
            echo "Connection established!";
        }
        mysql_close($con);
    ?>
</html>

But I keep getting the following error message:

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to MySQL server on ‘localhost’ (10061) in C:\xampp\htdocs\database_connect.php on line 5
Could not connect: Can’t connect to MySQL server on ‘localhost’ (10061)

Here are the troubleshooting steps I took:

  • Checked whether mysqld is running in Windows Task Manager Processes – it is
  • Checked whether MySQL was running on the host by typing in Windows command prompt: “telnet 192.0.0.1 3306” and got the message “Could not open connection to the host, on port 3306: connection failed”
  • Checked whether Windows Firewall was blocking MySQL – MySQL is an exception.

How do I get this code to work safely? And how do I check basic useful information about my MySQL like username?

  • 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-13T15:07:59+00:00Added an answer on May 13, 2026 at 3:07 pm

    You can check that the MySQL server is bound to port 3306 using tcpview. More simply, drop the port from the host specifier. The driver should then attempt to use a named pipe, rather than a TCP socket.

    On an unrelated note, I strongly urge you to switch to the PDO MySQL driver. The one you’re using is terribly out of date. One big advantage is PDO supports prepared statements, which offer security and efficiency benefits.

    Edit:

    This doesn’t answer your main question, but posting this information in a comment would be a mess.

    Rather than W3Schools, check out the resources suggested in:

    • What is the best PHP programming book?
    • PHP tutorial that is security-, accuracy- and maintainability-conscious?
    • Good Resources for Relational Database Design
    • Relational database theory and SQL book recommendations?
    • How should a programmer learn great database design?
    • Database Design Best Practices
    • Best Book for a new Database Developer
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.