Bug #12168 Updated: mysql_select_db() won't work
| From: | DeadEye5000 at hotmail dot com | Date: | Thu, 19 Jul 2001 20:15:16 +0000 |
| Subject: | Bug #12168 Updated: mysql_select_db() won't work | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-60330@lists.php.net to get a copy of this message | ||
ID: 12168
User updated by: DeadEye5000@hotmail.com
Reported By: DeadEye5000@hotmail.com
Status: Open
Bug Type: MySQL related
Operating System: Windows 2000
PHP Version: 4.0.6
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2001-07-14 12:24:43] DeadEye5000@hotmail.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.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12168&edit=1