How do I query the coppermine database? How do I query the coppermine database?
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How do I query the coppermine database?

Started by dreams83, March 10, 2007, 06:34:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dreams83

I want to query the coppermine database from inside coppermine but don't know how to get a working connection to the database.

<?php

define
('IN_COPPERMINE'true);
define('LOGIN_PHP'true);

require(
'include/init.inc.php');

pageheader("Song Lyrics");


starttable('-1'"Song Lyrics",2);//$lang_login_php['enter_login_pswd'], 2);

echo <<< EOT

<tr>
  <td class="tableb" >
      <table width="600px" cellspacing="2" cellpadding="2">
        <tr>
          <td><textarea cols="80" rows="10" wrap="virtual">
EOT;
//Running some dataquerry code here
                                        // I want to fetch some details for a files i have on the database from within coppermine
                                        // But I don't know who to use it. I was looking at the function include file and got this
                                        // After getting result from the database I know what to do but right now I don't know how
                                        // To fetch the details from the database. Maybe I an missing some function to connect to the database first
       $query "SELECT * from {$CONFIG['TABLE_PICTURES']} WHERE ( pid = 232 OR pid= 232 )";
                                       
$result cpg_db_query($query);

//End running my 
echo <<< EOT
</textarea></td>
        </tr>
      </table>
   </td>
</tr>
EOT;


endtable();

pagefooter();
ob_end_flush();

?>



I want to fetch some details for a files i have on the database from within coppermine
But I don't know who to use it. I was looking at the function include file and got this
After getting result from the database I know what to do but right now I don't know how
To fetch the details from the database. Maybe I an missing some function to connect to the database first

So I need some help to get a working connection to the database.

Thank You

dreams83

It works. Maybe something was wrong with me saving it before so it doesn't work.
But the file is working.

Sorry again.

Joachim Müller

Thanks for returning and resolving your thread.
The code you posted just runs the query against the database, but it doesn't do anything with the results. For reference for others, you might want to post your code as well that actually does something with the query results.

dreams83

I add another option to save lyrics to song on my site eHmongMusic.com at text file on the server.

So I used the code above to get the title from the database corresponding to the the text file on the server. by the way the text file are saved as pid.txt Ex. 232.txt    4632.txt and such.


<?php

define
('IN_COPPERMINE'true);
define('LOGIN_PHP'true);

require(
'include/init.inc.php');

// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts 
$filter ".txt";
// path to the directory you want to scan
$directory "lyrics";


// read through the directory and filter files to an array
@$d dir($directory);
if (
$d) { 
while($entry=$d->read()) {  
$ps strpos(strtolower($entry), $filter);
if (!($ps === false)) {  
$items[] = "pid=".str_replace(".txt",""$entry); 

}
$d->close();
sort($items);
//foreach ($items as $key => $val) {
   
// echo "items[" . $key . "] = " . $val . "<br/>";
//}
$comma_separated implode(" OR "$items);
        
//Setting the PID so that I could use mysql "WHERE ( pid=232 OR pid=544 OR pid=32 )" and so on
}


pageheader("Song with Lyrics");


starttable('-1'"Song with Lyrics",2);//$lang_login_php['enter_login_pswd'], 2);

echo <<< EOT

<tr>
  <td class="tableb" >
      <table width="600px" cellspacing="2" cellpadding="2">
        <tr>
          <td><!--<textarea cols="80" rows="10" wrap="virtual"> -->
EOT;

//Running some dataquerry code here

$query "SELECT * from {$CONFIG['TABLE_PICTURES']} WHERE ( $comma_separated ) ORDER BY title ASC";
                
$result cpg_db_query($query);
$counter 1;
//start table
echo "<table width=\"600\" border=\"0\">";
while ($row mysql_fetch_array($result)) {
//echo "<div style=\"width:auto\"><div style=\"width:30px\"><div style=\"float:left\">ID:</div><div style=\"float:right\">".$counter."</div></div></div><div>".$row{'title'}."</div></div>";

echo "<tr>";
echo "<td width=\"10\">ID:</td>";
echo "<td width=\"20\" align=\"right\">".$counter."</td>";
echo "<td width=\"500\" style=\"padding-left:10px\"><a href=\"displayimage.php?pos=-".$row{pid}."\">".$row{title}."</a></td>";
echo "</tr>";

$counter += 1;
}
//end table
echo "</table>";
mysql_free_result($result);
//End running my 
echo <<< EOT
<!--</textarea> --></td>
        </tr>
      </table>
   </td>
</tr>
EOT;


endtable();

pagefooter();
ob_end_flush();

?>


that is the php codes from my lyrics.php

This is what it looks like http://www.ehmongmusic.com/lyrics.php