Bug #12168: mysql_select_db() won't work
| From: | DeadEye5000 at hotmail dot com | Date: | Sat, 14 Jul 2001 16:24:43 +0000 |
| Subject: | Bug #12168: mysql_select_db() won't work | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-60035@lists.php.net to get a copy of this message | ||
From: DeadEye5000@hotmail.com
Operating system: Windows 2000
PHP version: 4.0.6
PHP Bug Type: MySQL related
Bug description: mysql_select_db() won't work
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.
--
Edit bug report at: http://bugs.php.net/?id=12168&edit=1