Correct syntax for MySQL database specification in Joomla?
Posted: Thu Jul 02, 2009 3:24 pm
I am trying to insert a custom PHP script via a Jumi component. I have written many similar PHP scripts before, but I can't seem to get my query (which works fine - tested on the server via MyPHPadmin) to run - I always receive the message, "No database selected."
Here is what is on the server, viewed through MyPHPadmin:
The database containing all of the Joomla tables is called mysite_joom
The table (in that same Joomla database) with the data I want to display is called librarybooks
MySQL connect works fine.
Here's my code:
<?
$db=mysql_connect ("localhost", "myusername",
"mypassword") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mysite_joom",$db);
$query= ('SELECT * FROM `librarybooks` WHERE `col3`="botany" ORDER BY `col2` ASC');
$result = mysql_query($query) or die(mysql_error());
?>
The result of this is "No database selected" I am sure this is something ridiculously simple, but I can't see it.
Here is what is on the server, viewed through MyPHPadmin:
The database containing all of the Joomla tables is called mysite_joom
The table (in that same Joomla database) with the data I want to display is called librarybooks
MySQL connect works fine.
Here's my code:
<?
$db=mysql_connect ("localhost", "myusername",
"mypassword") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mysite_joom",$db);
$query= ('SELECT * FROM `librarybooks` WHERE `col3`="botany" ORDER BY `col2` ASC');
$result = mysql_query($query) or die(mysql_error());
?>
The result of this is "No database selected" I am sure this is something ridiculously simple, but I can't see it.