Wrox Programmer Forums
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2005, 01:04 PM
Registered User
 
Join Date: May 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default coding

what's wrong....

<?php
//common_db.inc
$dbhost = 'localhost';
$dbusername = 'phpuser';
$dbuserpassword='phppass';
$default_dbname= 'mysql';

$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';

function db_connect() ?> {
    global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
    global $MYSQL_ERRNO, $MYSQL_ERROR;

    $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
    if (!$link_id) {
        $MYSQL_ERRNO = 0;
        $MYSQL_ERROR = "Connection failed to the host $dbhost.";
        return 0;
    }
    else if(empty($dbname) && !mysql_select_db($default_dbname)) {
        $MYSQL_ERRNO = mysql_errno();
        $MYSQL_ERROR = mysql_error();
        return 0;
    }
    else return $link_id;
}

    function sql_error() {
    global $MYSQL_ERRNO, $MYSQL_ERROR;

    if(empty($MYSQL_ERROR)) {
        $MYSQL_ERRNO = mysql_errno();
        $MYSQL_ERROR = mysql_error();
    }
    return "$MYSQL_ERRNO: $MYSQL_ERROR";
}


and I got this error message

Parse error: parse error, unexpected ';', expecting '{'

 
Old May 28th, 2005, 07:40 PM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

From what I can see, you ended your php too early. The entire function should be scripted out, rather then ending it after the "function db_connect() ?> {", the ?> should come after your "return "$MYSQL_ERRNO: $MYSQL_ERROR";", or something along those lines. As it is now, the script knows you made a function - it simply doesn't know what to do when you call it, or where the function starts.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with coding Gini Visual Studio 2008 2 March 6th, 2009 04:14 PM
Coding Help sugunakar Classic ASP Professional 2 March 30th, 2008 04:42 PM
help with coding mastrgamr C++ Programming 15 November 10th, 2006 07:55 AM
Help coding here Scoob PHP How-To 3 January 26th, 2006 11:18 AM
can someone help me in coding this? somanchivasu Access 1 April 5th, 2004 02:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.