SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse error: syntax error

    Parse error: syntax error, unexpected T_STRING, expecting ')' in .....sources\sql\mysql.php on line 26


    <?php
    //=================================================================\\
    // Aardvark Topsites PHP 5.0 \\
    //-----------------------------------------------------------------\\
    // Copyright 2003-2004 Jeremy Scheff - http://www.aardvarkind.com/ \\
    //-----------------------------------------------------------------\\
    // This program is free software; you can redistribute it and/or \\
    // modify it under the terms of the GNU General Public License \\
    // as published by the Free Software Foundation; either version 2 \\
    // of the License, or (at your option) any later version. \\
    // \\
    // This program is distributed in the hope that it will be useful, \\
    // but WITHOUT ANY WARRANTY; without even the implied warranty of \\
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \\
    // GNU General Public License for more details. \\
    //=================================================================\\

    $database = 'MySQL';

    class sql {
    var $dbl;
    var $debug;
    var $num_queries;
    var $queries;

    function connect (localhost, $user, $password, $database, $debug = 0) {
    $this->dbl = mysql_connect(localhost, $user, $password) ;
    $db = mysql_select_db($database, $this->dbl);

    $this->num_queries = 0;
    $this->debug = $debug ? 1 : 0;
    $this->queries = array();

    return $db;
    }

    function query($query, $file, $line) {
    global $queries;

    if ($this->debug) { array_push($this->queries, $query); }

    $result = mysql_query($query) or $this->error($file, $line);
    $this->num_queries++;

    return $result;
    }

    // Executes a normal query and fetches the array in one line
    function fetch($query, $file, $line) {
    $result = $this->query($query, $file, $line);
    return $this->fetch_array($result);
    }

    function select_limit($query, $num, $offset, $file, $line) {
    if ($offset) { $limit = ' LIMIT '.$offset.','.$num; }
    else { $limit = ' LIMIT '.$num; }

    return $this->query($query.$limit, $file, $line);
    }

    function fetch_array($result) {
    return mysql_fetch_array($result);
    }

    function num_rows($result) {
    return mysql_num_rows($result);
    }

    function escape($value, $no_html = 0) {
    if (get_magic_quotes_gpc()) {
    $value = stripslashes($value);
    }
    $value = mysql_real_escape_string($value, $this->dbl);

    if ($no_html) {
    $value = strip_tags($value);
    }

    return $value;
    }

    function error($file, $line) {
    trigger_error('Database error in "'.$file.'" on line '.$line.'<br /><br />'."\n".@mysql_error($this->dbl), E_USER_ERROR);
    }

    function close() {
    mysql_close($this->dbl);
    }
    }
    ?>

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    change line 26 to:
    PHP Code:
    function connect (localhost$user$password$database$debug) {
    $debug 0
    That should work. I've never worked with functions with values set inline, so i'm not sure what that means.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    change line 26 to:
    PHP Code:
    function connect (localhost$user$password$database$debug) {
    $debug 0
    That should work. I've never worked with functions with values set inline, so i'm not sure what that means.
    That won't work, $debug will always be 0 if you do that. The real error is localhost you for got the prefix it with $.

    for $debug = 0, that is a default value if it is not passed during calling.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah, I see.

    So how would you call that function?
    would it be
    PHP Code:
    connect("localhost""username""password""db_name"
    or
    PHP Code:
    connect("localhost""username""password""db_name", ) 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    arkinstall -- the former, no trailing comma. There can be multiple arguments with default values.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys.

    Oh, SymonHybrid, just put a $ in front of the two "localhost"s.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •