< MySQL
Content added Content deleted
No edit summary |
No edit summary |
||
Line 20: | Line 20: | ||
FLUSH PRIVILEGES; |
FLUSH PRIVILEGES; |
||
</pre> |
</pre> |
||
Testscript (written in PHP): |
|||
</pre> |
|||
<?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 "<table>\n"; |
|||
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { |
|||
echo "\t<tr>\n"; |
|||
foreach ($line as $col_value) { |
|||
echo "\t\t<td>$col_value</td>\n"; |
|||
} |
|||
echo "\t</tr>\n"; |
|||
} |
|||
echo "</table>\n"; |
|||
/* Free Resultset */ |
|||
mysql_free_result($result); |
|||
/* Close Connection */ |
|||
mysql_close($link); |
|||
?> |
|||
<pre> |
|||
[[Category:Computer]] |
[[Category:Computer]] |
||
[[Category:Programs]] |
[[Category:Programs]]</pre> |
Revision as of 18:46, 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);
?>
[[Category:Computer]] [[Category:Programs]]