Jump to content

Recommended Posts

Hey there again,

 

I have come across a minor hiccup in my adventure of learning php.

What I am doing is setting up an 'if' statement that lets a user type in their mySQL database username, and i want to find out if there is a php function that lets me get the 'mySQL database username' e.g. 'root'

Code so far:

<?php
if($_POST["mysql_user"] != FUNCTION TO FIND MYSQL USER)
        {
                echo
                        "
                        <br />
                        <br />
                        <b>MySQL Username does not exist</b>
                        ";
        }
?>

Link to comment
https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/
Share on other sites

You would first need to connect to the database with a name that can read mysql.user in there is where the user list is contained, but if your using shared hosting, you may not have access to this. If you do have access to this you may not want to have the shared user name that reads this list to have write access.

<?
$my_user = $_REQUEST['mysql_user'];

//connects to server
//replace "YourPassword" with your password
$connect = mysql_connect("localhost", "root", "YourPassword");

//selects the database on that server
//replace "YourDatabaseName" with your database name
mysql_select_db("YourDatabaseName", $connect);

//searches the database 
//replace "YourTableName" with a valid table name in that database
$result = mysql_query("SELECT * FROM `YourTableName` WHERE user='$my_user' ");

//checks to see if there was at least 1 user found
if(mysql_num_rows($result) > 1){
    

    $row = mysql_fetch_array($result);
    echo $row['user'];

}else{

    echo "No User found!";
}


?>

Hmm it seems i havent explained my question well enough..

In phpMyAdmin, there is a privileges section, where it lists out users who can create,change,delete databases etc. What i want to know is, is this:

is there a php function that finds out THESE usernames.

<?
$my_user = $_REQUEST['mysql_user'];

//connects to server
//replace "YourPassword" with your password DEFAULT IS BLANK
$connect = mysql_connect("localhost", "root", "YourPassword");

//selects the database on that server
mysql_select_db("mysql", $connect);

//searches the database 
//replace "YourTableName" with a valid table name in that database
$result = mysql_query("SELECT * FROM `users`");

while($row=mysql_fetch_array($result)){
echo $row['User'];
}

didnt know you wanted password aswell here. ALL YOU HAVE DO DO IS REPLACE "YourPassword" WITH YOUR MYSQL ROOT PASSWORD

<?
//replace "YourPassword" with your password DEFAULT IS BLANK
$connect = mysql_connect("localhost", "root", "YourPassword");


mysql_select_db("mysql", $connect);


$result = mysql_query("SELECT * FROM `users`");

while($row=mysql_fetch_array($result)){
echo "UserName: ".$row['User']." Password: ".$row[Password]."<br>\n";
}
?>

Hmm it seems i havent explained my question well enough..

In phpMyAdmin, there is a privileges section, where it lists out users who can create,change,delete databases etc. What i want to know is, is this:

is there a php function that finds out THESE usernames.

 

Yes.. at the config.inc.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.