Hello everyone!

I am having a problem. I receive an error below.

Parse error: syntax error, unexpected ')', expecting '(' in /home/fundis/public_html/ww.incs/basics.php on line 27

Here is my 'basics.php'.

<?php
session_start();

function __autoload($name) {
require $name . '.php';
}
function dbInit(){
if(isset($GLOBALS['db']))return $GLOBALS['db'];
global $DBVARS;
$db=new PDO('mysql:host='.$DBVARS['hostname']
.';dbname='.$DBVARS['db_name'],
$DBVARS['username'],
$DBVARS['password']
);
$db->query('SET NAMES utf8');
$db->num_queries=0;
$GLOBALS['db']=$db;
return $db;
}
function dbQuery($query){
$db=dbInit();
$q=$db->query($query);
$db->num_queries++;
return $q;
function dbRow($query) {
$q = dbQuery($query);
return $q->fetch (PDO::FETCH_ASSOC);
}
}

define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/');
require SCRIPTBASE . '.private/config.php';
if(!defined('CONFIG_FILE'))
define('CONFIG_FILE',SCRIPTBASE.'.private/config.php');
set_include_path(SCRIPTBASE.'ww.php_classes'
.PATH_SEPARATOR.get_include_path());

I would be grateful if you could help me solving that problem.

Thank you.

Tibor

The closing curly bracket } on line 28 should actually be just after line 24 (at the end of the function dbQuery). These things are quite easy to spot if you use indentation and editor with syntax highlighting.

<?php
session_start();

function __autoload($name) {
    require $name . '.php';
}
function dbInit(){
    if(isset($GLOBALS['db']))return $GLOBALS['db'];
        global $DBVARS;
    $db=new PDO('mysql:host='.$DBVARS['hostname']
            .';dbname='.$DBVARS['db_name'],
        $DBVARS['username'],
        $DBVARS['password']
    );
    $db->query('SET NAMES utf8');
    $db->num_queries=0;
    $GLOBALS['db']=$db;
    return $db;
}
function dbQuery($query){
    $db=dbInit();
    $q=$db->query($query);
    $db->num_queries++;
    return $q;
}
function dbRow($query) {
    $q = dbQuery($query);
    return $q->fetch (PDO::FETCH_ASSOC);
}

define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/');
require SCRIPTBASE . '.private/config.php';
if(!defined('CONFIG_FILE'))
    define('CONFIG_FILE',SCRIPTBASE.'.private/config.php');
set_include_path(SCRIPTBASE.'ww.php_classes'
    .PATH_SEPARATOR.get_include_path());  
?>

Thank you, but it still says the same as i copied your php syntax, but now it found the problem in the 28th line.

Any other ideas?!

Thanks.

What is the error message?

There is some problem with the --> return $q->fetch (PDO::FETCH_ASSOC); line i think.

Member Avatar for diafol
return $q->fetch(PDO::FETCH_ASSOC);

try without the space between fetch and '(' - but I don't think that's the issue though.

I've already tried it, but thank you. :(

And what if the problem comes from my PHP or Mysql setup?

Because I am really dummie with setup.

Beats me. Brackets seem to be fine. I can not understand why sysntax error.

If you really can't find a solution, might just be worth using trial and error; try inserting an extra bracket here and there.

Or cut all of your code into a separate document, and piece by piece add it back, testing each part?

I know it's a bit of a long shot.

Maybe you should check the included .private/config.php file. Maybe there is bracket missing in it? Maybe you could post it (remove passwords first if any).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.