On Jul 13, 2009, at 4:40 PM, Daniel Brown wrote:
On Mon, Jul 13, 2009 at 17:24, Govinda<govinda.webdnatalk@xxxxxxxxx>
wrote:
"No database selected"
You're getting warmer....
How would you select a MySQL database in PHP? (Hint: there's a
built-in function.)
To try and follow your lead and focus just on what you are saying, to
be rid of that first error that said "No database selected",
I changed the code back to this:
$db_billing=mysql_connect(localhost,metheuser,mypass,billing);
if (!$db_billing) { die('Could not connect: ' . mysql_error()); }
//$sql = "SHOW TABLES FROM billing LIKE 'mytable'";
$sql = "SHOW TABLES"; //line 237
//$result = mysql_query($sql);
$result = mysql_query($sql,$db_billing) or die(mysql_error());
//$result = $db_billing->query("$sql") or die(mysql_error()); // line
241
foreach(mysql_fetch_assoc($result) as $k => $v) { //line 243
//{DESCRIBE | DESC} tbl_name [col_name | wild]
$ssql = "DESCRIBE ".mysql_real_escape_string($v);
//$ssql = "DESCRIBE mytable ".mysql_real_escape_string($v); //line 246
$rresult = mysql_query($ssql);
echo "<b>".$k."</b>:<br />\n";
echo "<pre>\n";
print_r(mysql_fetch_assoc($rresult)); //line 250
echo "</pre>\n";
echo "<br />\n";
}
The question is why does line 240 think that no db is selected?!
I read the docs for mysql_query and it says:
resource mysql_query ( string $query [, resource $link_identifier ] )
so that 2nd param is optional; "If the link identifier is not
specified, the last link opened by mysql_connect() is assumed".
But anyway I stuck it in there too, to test, and I get the same
result, i.e. "No database selected".
I tried line 241 too. No luck.
So I am really stumped (lame as that feels/sounds). Line 237 is just
a string assignment. Line 240 *IS* being handed the $link to use,
which AFAIK means a reference to the database as well as the table, so
why the error?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php