Connect in a different page ? Connect in a different page ?
 

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

Connect in a different page ?

Started by isa150183, July 15, 2005, 01:13:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

isa150183

Hello,  sorry for my english, i'm french !

I have done a webpage with this to have the theme.
How can i do to connect the database in this page ?


<?php

define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('titre');
?>



<?php
[b]
//HERE IS IT OK OR DOES IT EXIST A BEST CODE ?
$db mysql_connect('IP''Base''passe')  or die('Erreur de connexion '.mysql_error());
mysql_select_db('base',$db)  or die('Erreur de selection '.mysql_error()); 
[/
b]
$sql 'SELECT .... desc limit 5'

// on envoie la requête 
$req mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); 

// on fait une boucle qui va faire un tour pour chaque enregistrement 
echo "<br><br><b>Liste  : </b><br><br>";
while(
$data mysql_fetch_assoc($req)) 
    { 
    
// on affiche les informations de l'enregistrement en cours 
    
echo '<b>'.$data['nom'].' '.$data['prenom'].'</b> ('.$data['nomconcours'].')'
    echo 
' <i>date : '.$data['date'].'</i><br>'
    } 
?>


<?php

pagefooter
();
?>



Thank you for all !!

Abbas Ali

There is no need to connect to the database if the database is same as cpg's database.  The connection already stands established since you are including init.inc.php in your script. You can directly use db_query() function to fire the query and fetch the results using mysql_fetch_row or other some other function.
Chief Geek at Ranium Systems

isa150183


isa150183

Can you post the code i have to put on my first code here ?
thank you a lot !!

Abbas Ali

The code below is useful only if the table from which u are trying to retrieve the data and the cpg tables are in same database


<?php

define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');
pageheader('titre');

$sql 'SELECT .... desc limit 5';

// on envoie la requête
$req db_query($sql);

// on fait une boucle qui va faire un tour pour chaque enregistrement
echo "<br><br><b>Liste  : </b><br><br>";
while(
$data mysql_fetch_assoc($req))
    {
    
// on affiche les informations de l'enregistrement en cours
    
echo '<b>'.$data['nom'].' '.$data['prenom'].'</b> ('.$data['nomconcours'].')';
    echo 
' <i>date : '.$data['date'].'</i><br>';
    }
?>


<?php

pagefooter
();
?>

Chief Geek at Ranium Systems

isa150183

Thank you very much, that is exactly that i want !
thanks a lot