Monday, 15 February 2010

mysql - Simple PHP Database Connections -



mysql - Simple PHP Database Connections -

i making simple page test database connection. when tried accessing browser, says:

server error

the website encountered error while retrieving http://localhost:8888/blah/blah/test.php. may downwards maintenance or configured incorrectly.

here suggestions:

reload webpage later. http error 500 (internal server error): unexpected status encountered while server attempting fulfill request.

all doing connecting database , displaying tables. here have far php code:

<?php // variables $dbname = $_get["dbname"]; $dbusername = $_get["dbusername"]; $dbpass = $_get["dbpass"]; $dbhost = $_get["dbhost"]; $connection = mysql_connect("$dbhost","$dbusername","$dbpass"); if (!$connection) { die('could not connect: ' . mysql_error()); } else { echo "connected"; $dbcheck = mysql_select_db("$dbname"); if (!$dbcheck) { echo mysql_error(); }else{ echo "<p>successfully connected database '" . $database . "'</p>\n"; // check tables $sql = "show tables `$database`"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { echo "<p>available tables:</p>\n"; echo "<pre>\n"; while ($row = mysql_fetch_row($result)) { echo "{$row[0]}\n"; } echo "</pre>\n"; } else { echo "<p>the database '" . $database . "' contains no tables.</p>\n"; echo mysql_error(); } } // code mysql_close($con); ?>

my error in wamp apache logs is:

[03-feb-2013 22:47:37 utc] php parse error: syntax error, unexpected end of file in /applications/mamp/htdocs/coursemanager/default/verify1.php on line 52

what unexpected end of file be?

you forgot } on end close: else{ echo "connected";

<?php // variables $dbname = $_get["dbname"]; $dbusername = $_get["dbusername"]; $dbpass = $_get["dbpass"]; $dbhost = $_get["dbhost"]; $connection = mysql_connect("$dbhost", "$dbusername", "$dbpass"); if (!$connection) { die('could not connect: ' . mysql_error()); } else { echo "connected"; $dbcheck = mysql_select_db("$dbname"); if (!$dbcheck) { echo mysql_error(); } else { echo "<p>successfully connected database '" . $database . "'</p>\n"; // check tables $sql = "show tables `$database`"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { echo "<p>available tables:</p>\n"; echo "<pre>\n"; while ($row = mysql_fetch_row($result)) { echo "{$row[0]}\n"; } echo "</pre>\n"; } else { echo "<p>the database '" . $database . "' contains no tables.</p>\n"; echo mysql_error(); } } } // code. no need close mysql , no need close php

php mysql database web server-side

No comments:

Post a Comment