Page 1 of 1
mysql_connect error
Posted: Tue Mar 22, 2005 11:14 pm
by ast3r3x
The error:
Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/16/d107262476/htdocs/swigg/sampler/index.php on line 5
From the start of the script to line 5:
Code: Select all
<?php
class DBase
{
$link = mysql_connect('address', 'user', 'pass');
I'm really confused, because I've used this before, but it seems like having it in my class causes problems. My first attempt at making a class too!

Posted: Tue Mar 22, 2005 11:20 pm
by John Cartwright
First of all, you never close your class..
secondly, you need to have your $link bit inside a function, you'll get errors if not.
Code: Select all
class NAME {
function NAME1() {
//do stuff here
}
}
is the proper format..
feyd | forgot the parens 
Posted: Tue Mar 22, 2005 11:33 pm
by ast3r3x
*sigh*
Way to easy to fix.
I did close my class I just only showed up to the 5th line because that is where it said the error was.
Thanks, I was under the impression you could put any code inside of a class you wanted to run when it was created.
Posted: Tue Mar 22, 2005 11:42 pm
by feyd
yes, you can.. inside the constructor. Unless the code is static return data, it won't fly, from what I remember.
Posted: Wed Mar 23, 2005 12:23 am
by ast3r3x
Thanks guys! (gals?)
I got my first class working, and it will save me a little code for when I make calls to my database. I have to say I wish my main webserver was running PHP5, it's so nice to develop on my system, but then when I upload, I have to change stuff around to get it working...so annoying.
Anwyays, again thanks, you got me started on simple OO...McGruff would be so proud

Posted: Wed Mar 23, 2005 1:10 am
by Pyrite
Well if you want a database class, I highly suggest you check out ADOdb!
Posted: Wed Mar 23, 2005 6:58 am
by ast3r3x
Thanks I'll check that out. Would ADOdb be overkill considering I just connect to my mysql database, perform simple queries?
Posted: Wed Mar 23, 2005 8:08 am
by Pyrite
No. They have some pretty useful functions and i think it is easier to use than php's mysql functions.
Posted: Wed Mar 23, 2005 8:29 am
by CoderGoblin
The debate of the need for database abstraction layers, such as ADOdb has been discussed before.If you aare new to database handling in PHP I would recommend you learn how to do it using core PHP before you look at database abstraction layers. Who knows you may get a job where ADOdb is not allowed or they have their own abstraction layer. Know the basics and implementing ADOdb becomes easier.
Posted: Wed Mar 23, 2005 8:40 am
by ast3r3x
Well by no means am I a pro, but I know how to work with mysql from php. My book actually taught me with pear, but I changed to just using mysql_functions.
I really only use connect, select_db, query, and fetch_array.
I guess I'll check out ADOdb then, if nothing else, can't hurt to learn something new.
Posted: Wed Mar 23, 2005 11:15 am
by Pyrite
I don't think i have ever heard of anyone who went straight into ADOdb without first learning php's mysql module.
I just find it easier to work with, in fact, if you ever want to change databases, no need to screw with your code. I think most companies would admire that bennefit don't you? (I know mine does).