velocite Posted March 10, 2008 Share Posted March 10, 2008 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 More sharing options...
velocite Posted March 10, 2008 Author Share Posted March 10, 2008 please help Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-488806 Share on other sites More sharing options...
DarkerAngel Posted March 10, 2008 Share Posted March 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-488810 Share on other sites More sharing options...
l0ve2hat3 Posted March 10, 2008 Share Posted March 10, 2008 <? $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!"; } ?> Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-488847 Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 oops change this if(mysql_num_rows($result) > 1){ to this if(mysql_num_rows($result) > 0){ Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489090 Share on other sites More sharing options...
velocite Posted March 11, 2008 Author Share Posted March 11, 2008 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. Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489211 Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 <? $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']; } Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489223 Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489227 Share on other sites More sharing options...
cyrixware Posted March 11, 2008 Share Posted March 11, 2008 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 Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489229 Share on other sites More sharing options...
cyrixware Posted March 11, 2008 Share Posted March 11, 2008 /* Authentication type and info */ $cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['extension'] = 'mysql'; Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489231 Share on other sites More sharing options...
velocite Posted March 11, 2008 Author Share Posted March 11, 2008 Thank u so much Link to comment https://forums.phpfreaks.com/topic/95356-mysql-database-username-and-pass/#findComment-489245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.