×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    MySQL/Create User: Difference between revisions

    Content added Content deleted
    No edit summary
    No edit summary
    Line 22: Line 22:


    Testscript (written in PHP):
    Testscript (written in PHP):

    </pre>
    <?php
    <?php
    /* Modification of a simple mysqlscript from php.net: http://www.php.net/mysql */
    /* Modification of a simple mysqlscript from php.net: http://www.php.net/mysql */
    Line 54: Line 54:


    ?>
    ?>

    </pre>


    [[Category:Computer]]
    [[Category:Computer]]

    Revision as of 18:47, 9 July 2005

    Dont use mysql-root because of lazyness ;)


    Create a new user "fnord" with password "foobar".:

    INSERT INTO mysql.user (user, host, password)
       VALUES ('fnord', 'localhost', PASSWORD('foobar'));
    

    Create a new database "grudnuk":

    CREATE DATABASE grudnuk;
    

    Give permissions to the user "fnord" on all tables of the db "grudnuk":

    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP
       ON grudnuk.* TO fnord;
    

    Dont forget to update permissions:

    FLUSH PRIVILEGES;
    

    Testscript (written in PHP):

    <?php

      /* Modification of a simple mysqlscript from php.net: http://www.php.net/mysql */
    
      /* Connect to DB */
      $link = mysql_connect("localhost", "fnord", "foobar")
      or die("Cannot connect to mysql: " . mysql_error());
      echo "Connected!";
      mysql_select_db("grudnuk") or die("Cannot connect to DB");
    
      /* Execute a sql-statement (only if you already have some data in your new db*/
      $query = "SELECT * FROM tablename";
      $result = mysql_query($query) or die("Query not successful: " . mysql_error());
    
      /* HTML-Output */
    

    echo "

    \n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t\n"; foreach ($line as $col_value) { echo "\t\t\n";
      }
    
    echo "\t\n"; } echo "
    $col_value

    \n";

     /* Free Resultset */
     mysql_free_result($result);
    
     /* Close Connection */
     mysql_close($link);
    

    ?>

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.