Correct syntax for MySQL database specification in Joomla?

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.
Locked
cf1237
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 161
Joined: Thu Mar 19, 2009 1:48 pm

Correct syntax for MySQL database specification in Joomla?

Post by cf1237 » 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.

cf1237
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 161
Joined: Thu Mar 19, 2009 1:48 pm

Re: Correct syntax for MySQL database specification in Joomla?

Post by cf1237 » Thu Jul 02, 2009 7:03 pm

Misleading error message from Joomla. Database is selected correctly.

I ran an error check from outside Joomla and the error that came back was "Access denied...") A further check of this server shows that the proper syntax to CONNECT should be:

$db=mysql_connect ("localhost:/tmp/mysql5.sock", "myusername",
"mypassword")

Works fine, now. I dunno why Joomla output "No database selected," though.


Locked

Return to “Joomla! Coding 101”