php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12168 mysql_select_db() won't work
Submitted: 2001-07-14 12:24 UTC Modified: 2001-07-19 16:15 UTC
From: DeadEye5000 at hotmail dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.6 OS: Windows 2000
Private report: No CVE-ID: None
 [2001-07-14 12:24 UTC] DeadEye5000 at hotmail dot com
This is a two part script, query.php and mysqltest.php.  It's a script that executes a query on the selected database.  But I get an error that says that there is no database selected.  I'm using IIS 5.  This is the first page:

<html>
<head>
<title>PHP Code Tester</title>
</head>
<body>
<!-- query.php -->
<?
$host = "localhost";
$user = "dan";
$pass = "moops";
?>

<form action="mysqltest.php">
Please select the database for query:<br><br>
<select name=database>
<?
mysql_connect($host, $user, $pass);
$dbTable = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($dbTable); $i++) {
	echo "<option value=\"" . mysql_tablename($dbTable, $i) . "\">" . mysql_tablename($dbTable, $i) . "\n";
}
?>
</select>
<br><hr>
Please input the SQL Query to be executed:<br><br>
<textarea name="query" cols=50 rows=10></textarea><br><br>
<input type=submit value="Execute Query!">
</form>
</body>
</html>

Sorry if this is a bit long, but this is the second page:

<html>
<head>
<title>PHP SQL Code Tester</title>
</head>
<body>
<!-- mysqltest.php -->

<?
$host = "localhost";
$user = "dan";
$pass = "moops";

mysql_connect($host, $user, $pass);
$query = stripSlashes($query);
$result = mysql_db_query($database, $query);
?>

Results of query <b><? echo $query; ?></b><hr>

<?
if ($result == 0):
	echo "<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>";
elseif (mysql_num_rows($result) == 0):
	echo "Query executed successfully!</b>";
else:
?>
<table border=1>
	<tr>
		<?
		for ($i = 0; $i < mysql_num_fields($result); $i++) {
			echo "<td>" . mysql_field_name($result, $i) . "</td>";
		}
		?>
	</tr>
	<?
	for ($i = 0; $i < mysql_num_rows($result); $i++) {
		echo "<tr>";
		$rowArray = mysql_fetch_rows($result);
		for ($j = 0; $j < mysql_num_fields($result); $j++) {
			echo "<td>" . $rowArray[$j] . "</td>";
		}
		echo "</tr>";
	}
	?>
</table>

<? endif ?>

<hr><br>
<form action=query.php method=post>
	<input type=submit value="New Query">
</form>
</body>
</html>

I'm using the win32 binary of PHP.  While I was installing PHP it ran into an error saying it couldn't configure for IIS, and that I had to manually do it.  I set it up and all the scripts run fine except for when I have to select a database.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-19 16:15 UTC] DeadEye5000 at hotmail dot com
i actually fixed the problem...i dunno if this is why it wasn't working, but all i did was delete the mysql_connect() that was in the second page...now it works fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 03:01:29 2024 UTC