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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:31:05+00:00 2026-06-16T23:31:05+00:00

I am able to connect to the database by using the following code. <?php

  • 0

I am able to connect to the database by using the following code.

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

But, the above code is just to check whether the connection from PHP to MySQL server is established or not but its no way checking whether the database user is connected with the database name.

Well, I was trying to connect to the database in my project I am unable to connect to it. I have customized error report for that which is not clear but I am able to connect to the database server from PHP using

mysql_connect(servername,username,password);

So, can anybody suggest me some code to test whether the database user is authorized to connect to the database or not?

  • 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-06-16T23:31:06+00:00Added an answer on June 16, 2026 at 11:31 pm

    It can be done like this (using the mysqli extension) :

    <?php
    
    $link = @mysqli_connect('host', 'user', 'secret');
    if(!$link) {
        die('failed to connect to the server: ' . mysqli_connect_error());
    }
    
    if(!@mysqli_select_db($link, 'dbname')) {
        die('failed to connect to the database: ' . mysqli_error($link));
    }
    

    In my example I used the functional api to mysqli. This works the same way as in the older mysql extension.

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

Sidebar

Related Questions

I am currently using the following code to connect to a mysql database, but
I am able to connect to an Oracle database using several tools, but am
I am trying to connect to HP Operations Manager Database using Java code in
In cakephp I want to be able connect to a different database from one
I'm not able to connect a simple client and a simple server. When I
I'm getting an exception from Cruise Control about not being able to connect to
Good day to you all :) So I was using the following code to
I get this error when I try to connect to the mysql database using
I'm trying to connect to a Sybase database in Python (using the python-sybase DBAPI
As of last week, I was able to connect to my MySQL database (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.