PDA

View Full Version : [PHP] database access


gioele78
01-06-2009, 12:14 PM
I all!

new to PHP and pixelpost I'm trying to write a little own code but I cannot access to the database (otherwise pixelpost work perfectly).

The code I'm trying is

if(file_exists("includes/pixelpost.php")) { require("includes/pixelpost.php"); }
if(file_exists("includes/functions.php")) { require("includes/functions.php"); }

$query = "select headline,body,image from photo";

I also tried


if(file_exists("includes/pixelpost.php")) { require("includes/pixelpost.php"); }

function pixel_db_connect ()
{
$link = mysql_pconnect ("$pixelpost_db_host ","$pixelpost_db_user","$pixelpost_db_pass");
if ($link && mysql_select_db ("$pixelpost_db_pixelpost"))
return ($link);
return (false);
}

pixel_db_connect();
$query = "select headline,body,image from photo";

but I always get the error

Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a1900545/public_html/addons/_easyMap/generate_kml.php on line 24


Any help would be appreciated!

cheers,
gioele :)

Dennis
01-06-2009, 01:17 PM
obviously the file isn't included properly.

gioele78
01-06-2009, 03:06 PM
I tought so too
I made some attempt but I couldn't have success. The script works properly on my local machine, but if I try just

include 'includes/pixelpost.php';

I get the error:
Failed opening 'includes/pixelpost.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')

and on this directory have no permissions.

A example would be great!

tanks
gioele

dhdesign
01-06-2009, 11:39 PM
The error you are getting is because the path to includes/pixelpost.php is incorrect.

I am assuming from your last error that you are trying to write an addon? If so, then you should open an existing addon that comes default with Pixelpost, and look at the code to see how the database is accessed. For instance, this is a database query from admin_update_exif.php:

$query = "SELECT id,image FROM ".$pixelpost_db_prefix."pixelpost WHERE exif_info IS NULL";

In that file, there is an include statement to pull in includes/functions_exif.php:

include_once('../includes/functions_exif.php');

Notice the ../ - that means that the file has to go up one directory to find the file.

If your database table photo resides in the Pixelpost database, then here is what your code should look like:

if(file_exists("../includes/pixelpost.php")) {
include("../includes/pixelpost.php");
}
if(file_exists("../includes/functions.php")) {
include("includes/functions.php");
}

$query = "SELECT headline, body, image FROM ".$pixelpost_db_prefix."photo";

I changed require to include in the code, as require will cause a fatal error, but include will simply fail while the rest of the Pixelpost code continues to execute.

gioele78
01-08-2009, 05:22 PM
Hi! tanks for the help!

you should open an existing addon that comes default with Pixelpost, and look at the code

but I did it! this is what I found in the addon easymap
if (file_exists("includes/exifer1_5/exif.php"))

require_once("includes/exifer1_5/exif.php")

However, this code does not work by me (should it? I didn't really understand...):
if(file_exists("../../includes/pixelpost.php")) {
include("../../includes/pixelpost.php");
}
if(file_exists("../includes/functions.php")) {
include("../../includes/functions.php");
}

$query = "select headline,body,image from ".$pixelpost_db_prefix."pixelpost";

Bau this works, also I SOLVED!
if(file_exists("../../includes/functions.php")) { require("../../includes/functions.php"); }

if(file_exists("../../includes/pixelpost.php")) { require("../../includes/pixelpost.php");}

function pixel_db_connect ()
{
$link = mysql_connect ($GLOBALS['pixelpost_db_host'],$GLOBALS['pixelpost_db_user'] ,$GLOBALS['pixelpost_db_pass']);
if ($link && mysql_select_db ($GLOBALS['pixelpost_db_pixelpost']))
return ($link);
return (false);
}

pixel_db_connect();

$query = "select headline,body,image from ".$pixelpost_db_prefix."pixelpost";

A first version of my personalization of the easymap addons is here
http://tommaso.comze.com/ (http://http://tommaso.comze.com/)
(clic on "show this photo on a map" and "show me the world map")