-
I have a problem:
Have a look at
http://216.74.101.27/test.php
Now, either it is not working because the name hasn't been transfered yet or i have something wrong.
I am just copying the article supplied at Sitepoint to test MySQL out:
<HTML><HEAD><TITLE> Our List of Jokes </TITLE><HEAD><BODY>
<?php
$cnx = mysql_connect( "216.74.101.27", "*****", "*****");
if (!$cnx) {
echo( "<P><B>Unable to connect to the database server at this time.</B></P>" );
exit();}
mysql_select_db("petesmc_articles", $cnx);
if (! @mysql_select_db("petesmc_articles") ) {
echo( "<P>Unable to locate the joke database at this time.</P>" );
exit();}
if (! @mysql_select_db("petesmc_articles") ) {
echo( "<P>Unable to locate the joke database at this time.</P>" );
exit(); }
?>
<P> Here are all the jokes in our database: </P><BLOCKQUOTE>
<?php // Request the text of all the jokes
$result = mysql_query("SELECT JokeText FROM petesmc_articles");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
// Display the text of each joke in a paragraph
while ( $row = mysql_fetch_array($result) ) {
echo("<P><table width=50% border=3 bordercolor=blue><tr><td>" . $row["JokeText"] . "</td></tr></table></P>"); }
?>
</BLOCKQUOTE></BODY></HTML>
Any ideas?
-
Change
$cnx = mysql_connect( "216.74.101.27", "*****", "*****");
to
$cnx = mysql_connect( "localhost", "*****", "*****");
-
Thanx allot.
I got it working.
-
Can you rename a databse from telnet?
-
Not really you could use mysqldump to dump the tables to a text file then create a new database an import the tables back in
Step 1:
cd into the directory use
$> mysqldump -u username -p > db.sql
Step 2:
$> mysqladmin -u username -p CREATE dbname
Step 3:
$> mysql -u username -p newdbname < db.sql
Chenge username to be your username
NOTE: this will only work if you have rights to create databases
-
For some reason this doesn't work, same URL
----------
<HTML><HEAD><TITLE> Our List of Jokes </TITLE><HEAD><BODY><basefont face="verdana"><font size="2">
<?php
if (isset($addjoke)):?>
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA>
<BR><INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT"></FORM>
<?php else:
$dbcnx = @mysql_connect("localhost", "petesmc_peabug", "setcookie");
if (!$dbcnx) {
echo( "<P>Unable to connect to the database server at this time.</P>" );
exit(); }
if (! @mysql_select_db("petesmc_articles") ) {
echo( "<P>Unable to locate the joke database at this time.</P>" );
exit(); }
if ("SUBMIT" == $submitjoke) {
$sql = "INSERT INTO Jokes SET JokeText='$joketext', JokeDate=CURDATE()";
if (mysql_query($sql)) {
echo("<P>Your joke has been added.</P>"); }
else {
echo("<P>Error adding submitted joke: " . mysql_error() . "</P>"); }
}
echo("<P> Here are all the jokes in our database: </P>");
$result = mysql_query("SELECT JokeText FROM Jokes");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
while ( $row = mysql_fetch_array($result) ) {
echo("<P>" . $row["JokeText"] . "</P>");
}
while ( $row = mysql_fetch_array($result) ) {
echo("<P><table width=50% border=3 bordercolor=blue cellpadding=0 cellspacing=0><tr><td><blockquote><br>" . $row["JokeText"] . "</blockquote></td></tr></table></P>"); }
?>
</font></body></html>
---------
-
CD to what DIR, would SQL be on the same server?
-
to whatever dir it really doesn't matter yes MySQL should be running on the same server since you can connect to localhost
-
I would download phpMyAdmin to rename a database. It's basically a web-based interface to connect to your mySQL database. I'm new at this too and this program came in handy.
-
I have phpAdmin but i can't seem to rename
-
I am pretty darn sure that PHPMyAdmin cannot perform functions that MySQL cannot!
-
My mistake. phpMyAdmin will only let you rename tables, not the name of the database.
-
As I posted earlier, you can simply rename the directory in which the database is contained. (You may have to reset the permissions on that directory).
E.g. to rename "foo" to "bar", you would rename the folder "foo" to "bar" in your data dir in telnet.
-
Now what about the entries in your mysql table for users or hosts who have access to a specific database, you would need to change those as well. I think one should always avoid just changing the name of the data dir.