![]() |
| ||
| OOPing with PHP4 simple DB connect class? I am banging my head against the wall here. I've tried everything that I can think of to get this to work. class myData {
Note, I am also using a "require_once" of a file which holds variables for $connection = mysql_connect("localhost","maDB","maPassword") or die(mysql_error());
in my index page I have the following sql = "select * from tablename"; Using this method keeps giving me an error of unexpected T_CLASS... I've tried several other things, but I was almost sure that this was the way that it was sposed to work? All I am trying to do is create a generic connect to database and pass $sql as an argument, then store some information based on that as an array for each record that matches my request. I am using a PHP4 server. Any help? Thanks Sage |
| ||
| Re: OOPing with PHP4 simple DB connect class? There is nothing in the code that you posted that is actually causing the error. Look at my tutorial here which has a nice introduction to using database classes. Matti Ressler Suomedia |
| ||
| Re: OOPing with PHP4 simple DB connect class? Thanks for this tute, it's pretty good, although, I wouldn't recommend a beginning OOPer to read that right off the bat. I've been working with PHP OOPing for only a short time, but, as it's a daily requirement in my job, I find your stuff easier to follow than our own docs at work. The only thing is that I have never seen anything like line 17 before. function flowSQL($db_server = DATABASE_SERVER, $db_user = DB_USERNAME, $db_pass = DB_PASSWORD, $database = DATABASE)is this a PHP5 thing? I don't have access to 5 at the moment, err... scratch that.. I don't have access on the server that I am creating this for, to PHP5. I am assuming that, this line must stay as is, however, we need to use define('DATABASE_SERVER', 'localhost');
another item I am assuming is PHP5 which does not work in 4, as I have never seen it in a PHP4 script. further assumption is that, if I actually did all the defines, that this would globally define these items as long as I use some require page.php. At which point I would be able to do something like $query = "SELECT needle FROM haystack WHERE hay = yellow"; or is it even needed to use the second to last line? Thanks again for your help Sage |
| ||
| Re: OOPing with PHP4 simple DB connect class? Quote:
Did you forget the $ before sql in the code above? $sql = "select * from tablename"; That would probably generate a T_STRING error... As for the T_CLASS error, make sure you didn't forget to close open braces () or {} or are missing a ; at the end of your statements just before the class definition. |
| ||||
| Re: OOPing with PHP4 simple DB connect class? Quote:
No its not. It uses defines, eg. DATABASE_SERVER that are defined in the configuration file. Quote:
Thats exactly as I have it in the tutorial configuration file. The example given in the tutorial is pretty standard for any version of PHP. Quote:
Yes, you will see in the tutorial that your main page has: // include the configuration file and database class Quote:
Its better structured like this (less confusing): $dBase = new flowSQL; We still need to fetch our result however, eg: while($result = $dBase->fetch_array($query)) {
Matti Ressler Suomedia |
| ||
| Re: OOPing with PHP4 simple DB connect class? Great Matti, I shall try this over the weekend. The main reason for wanting to pass the var $sql as an arg, rather than type out the statement is because, there might be some dynamic stuff going on there as well, as in the case of say a search function, with advanced features. At any rate, I shall dig into your tute more deeply this weekend. Thanks Sage |
| All times are GMT -4. The time now is 10:43 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC