php - identified by password in the grant query affecting irrelevant connection -
in code below there 2 mysql connections, issue second connection gives connection error if password coming in form 123456.
now, password coming in form should have nothing second connection because password in new database made before second conenction starts. second connection connecting database together.
however, if use commented out $grantq query, second connection works fine. means issue got identified '{$pass}' in $grantq query.
the identified '{$pass}' query should affect new database has been created. why affecting existing db second connection connecting to?
please .. sorry long summary !
<?php if(isset($_post['submit'])){ // super connection $maindb_db = "little_maindb"; $maindb_server = "localhost"; $maindb_username = "admin@littlesidegym.com"; $maindb_password = "123456";// $conn = new mysqli($maindb_server, $maindb_username, $maindb_password, $maindb_db); if ($conn->connect_error) { die($contact_cus_supp); } //name of db post - customer view $new_dbname = mysqli_real_escape_string($conn, $_post['db_name']); $new_pass = mysqli_real_escape_string($conn, $_post['pass']); // creating database $sql = "create database if not exists $new_dbname "; if (!mysqli_query($conn, $sql)) { mysqli_close($conn); exit(); } $host = "localhost"; $user = $_session['sess_email']; $flush_pri = "flush privileges"; $pass = $new_pass; // grant user privileges echo $current_project; $grantq = "grant privileges on " . $new_dbname . ".* '{$user}'@'{$host}' identified '{$pass}'"; //$grantq = "grant privileges on " . $new_dbname . ".* '{$user}'@'{$host}'"; if(!mysqli_query($conn,$grantq)){ mysqli_close($conn); exit(); } if(!mysqli_query($conn,$flush_pri)){ mysqli_close($conn); exit(); } // super connection close mysqli_close($conn); // altogether different connection $secdb_db = "little_userdb"; $secdb_server = "localhost"; $secdb_username = "user@littlesidegym.com"; $secdb_password = "123456";// $conn = new mysqli($secdb_server, $secdb_username, $secdb_password, $secdb_db); if ($conn->connect_error) { die($contact_cus_supp); } echo "hello world"; ?> // form
echo '<table>'; echo '<form action="create_project.php" method="post" id = "myform" name = "myform" >'; echo '<tr><th></th></tr><tr><td><input type = "text" value="" name = "db_name" class = "req alphanums" placeholder = "db name" ><td></tr>'; echo '<tr><th></th></tr><tr><td><input type = "password" value="" name = "pass" class = "req" placeholder = "password" ><td></tr>'; echo '<tr><th></th></tr><tr><td><div id = "submit"><input type="submit" id = "submit" name = "submit" value = "create project"></div><td></tr>'; echo '</form>'; echo '</table>';
you using same user name newly created database , accessing little_userdb, changing password each time.
in mysql user identified name , hostname mask (mysql looks first match). code changes password existing user , grants him access new db.
Comments
Post a Comment