Jump to content
DevFuse Forums

Basic php file production


najaru

Recommended Posts

Hi michael.

 

I try to understand how to transform a basic php file to a ipb integrate file (i want just to dont have hany connection to database.

 

The file is this one (but i am not interested in this file, i whant just to print a list of one table fields.... or even just one field..... it's just for understand):

 

<?php

   $conn=  mysql_connect('localhost','ipb','ipb');
   if(!$conn)die(mysql_error($conn));
   $ris=mysql_select_db("ipb",$conn);
   if(!$ris)die(mysql_error());
?>

<html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 </head>
 <body>
   <?php
    $idf="2";

       $msg="SELECT * FROM `topics`where forum_id=$idf ORDER BY `start_date` DESC LIMIT 0, 3 ";

       $query=mysql_query($msg);
       if(!$query) die(mysql_error());
       $l="";
       while($row= mysql_fetch_assoc($query)){
           //Confronto
           if(strcasecmp($l,substr($row['title'],0,1))!=0){
               $l=substr($row['title'],0,1);
       ?>

   <?php

                   }
               ?>
   <a href="index.php?/topic/<?php echo $row['tid']."-".$row['title'] ?>" target="_blank">
   <?php echo  $row['title']?></a><?php if($row['description']!="") echo ("<font color='#000000'> - ".$row['description']."</font>") ?> <?php echo $row['seo_first_name']?></br>
   <?php } ?>
 </body>
</html>



 

in first php section there is the database connection

$conn= mysql_connect('localhost','name','password');

 

Terabyte tell to use this:

require_once( 'initdata.php' );
require_once( CP_DIRECTORY.'/sources/base/ipsRegistry.php' );
require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );

$registry = ipsRegistry::instance();
$registry->init();

 

and this:

ipsRegistry::DB()->funcName();

 

but i dont understand how to use this.

 

My php is very very very very low level......

Edited by najaru
Link to comment
Share on other sites

  • Management

For your database connection, you can load up your forums conf_global.php file and use the login details from there. I use something similar on the main site here, I haven't had a chance to look into loading the IPB registry yet.

 

	require_once( "/path_to_forum_folder/conf_global.php" );
$INFO[] = array();

 	$username    = $INFO['sql_user'];
 	$database    = $INFO['sql_database'];
 	$password    = $INFO['sql_pass'];
$mysql       = "localhost";
 	$tableprefix = $INFO['sql_tbl_prefix'];

mysql_connect($mysql,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 

       $msg="SELECT * FROM `{$tableprefix}topics` where forum_id=$idf ORDER BY `start_date` DESC LIMIT 0, 3 ";
       $query=mysql_query($msg);

 

For your second script there, your testing this file in the same directory of your initdata.php file? So it can find the file?

Link to comment
Share on other sites

  • Management

question: why this file work only if is in the same folder of config file?

 

It doesn't really need to be, as long as the path to the config file is setup, you can have them in different folders. So if you wanted this file on the home page and your forums are in a /forums/ folder, you'd need to make sure the path is correct.

Link to comment
Share on other sites

  • Management

If your file is going to be a directory below your forums folder you would need to change it to this. You can also put in the full path to the file (depends on your server) e.g. /home/username/public_html/forums/

 

require_once( "../forums/conf_global.php" );

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...