SQL Connection?

Gesperrt
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

SQL Connection?

Beitrag von djavet »

Hello

I try to implenant a search module and I can't connect to the DB, may I ask help?

And how may I replace the table prefix?

The code:

Code: Alles auswählen

<?php

include_once ("config.php");
include_once ($contenido_path . "includes/config.php");
include_once ($contenido_path . "includes/startup.php");

cInclude("includes", "functions.con.php");
cInclude("includes", "functions.con2.php");
cInclude("includes", "functions.api.php");
cInclude("includes", "functions.pathresolver.php");

include_once($cfg["path"]["contenido"].$cfg["path"]["includes"]."functions.con.php");


$dbConnect = new DB_Contenido;

//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/xml; charset=utf-8");


///Make sure that a value was sent.
if (isset($_GET['search']) && $_GET['search'] != '') {
	//Add slashes to any quotes to avoid SQL problems.
	$search = addslashes($_GET['search']);
	//Get every page title for the site.
	$suggest_query = @mysql_query("SELECT keyword FROM con__keywords WHERE like('%".$search."%') order by keyword limit 15");
	while($suggest = db_fetch_array($suggest_query)) {
		//Return each page title seperated by a newline.
		echo $suggest['suggest'] . "\n";
	}
}
?>

Thx a lot ion advance.
Regards, Dominique
stese
Beiträge: 1040
Registriert: Fr 3. Dez 2004, 17:47
Wohnort: München
Kontaktdaten:

Beitrag von stese »

at first: before you code some modules, please take a look in other contenido files or contenido modules!

if you use a contenido module (and no single php file) the first include lines are not necessary!

to take db queries, please use the database object from contenido! you initialize this db objekt in one of the first lines:

Code: Alles auswählen

$dbConnect = new DB_Contenido;
please take a look in other modules or php files from contenido to understand the methods of this db object.

to take a sql query you should use the "query" method

Code: Alles auswählen

$dbConnect->query("SELECT * FROM somewhere");
if you want to access a single record, you have to use the "next_record" in the second step:

Code: Alles auswählen

$dbConnect->next_record();
and if you have more than one results you have to wirte this method in a loop:

Code: Alles auswählen

while ($dbConnect->next_record()) {
if you want to access a database field in the current record, use the "f" method:

Code: Alles auswählen

print $dbConnect->f("fieldname");
djavet
Beiträge: 264
Registriert: Do 22. Jan 2004, 11:31
Kontaktdaten:

Beitrag von djavet »

Thx for your help.
I've looked at first at the menu module.

Now it's working. I'm not a php expert. I'm learning.

Regards, Dom
Gesperrt