| | |
OOPing with PHP4 simple DB connect class?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
I am banging my head against the wall here.
I've tried everything that I can think of to get this to work.
Note, I am also using a "require_once" of a file which holds variables for
in my index page I have the following
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
I've tried everything that I can think of to get this to work.
PHP Syntax (Toggle Plain Text)
class myData { function myStuff($sql){ $result = @mysql_query($sql,$connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $adId = $row['adId']; $adName = $row['adName']; $adData .= "my adId is $adId and guess what? my adName is $adName <br/><br/>"; } } }
Note, I am also using a "require_once" of a file which holds variables for
PHP Syntax (Toggle Plain Text)
$connection = mysql_connect("localhost","maDB","maPassword") or die(mysql_error()); $db_name = "myDB"; $db = @mysql_select_db($db_name,$connection) or die(mysql_error);
in my index page I have the following
PHP Syntax (Toggle Plain Text)
sql = "select * from tablename"; $objAdvertisers = new myData; $objAdvertisers->myStuff($sql);
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
•
•
Join Date: Mar 2008
Posts: 154
Reputation:
Solved Threads: 19
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
Look at my tutorial here which has a nice introduction to using database classes.
Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
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.
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
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
or is it even needed to use the second to last line?
Thanks again for your help
Sage
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.
PHP Syntax (Toggle Plain Text)
function flowSQL($db_server = DATABASE_SERVER, $db_user = DB_USERNAME, $db_pass = DB_PASSWORD, $database = DATABASE)
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
PHP Syntax (Toggle Plain Text)
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
PHP Syntax (Toggle Plain Text)
$query = "SELECT needle FROM haystack WHERE hay = yellow"; $myQuery = new flowSQL; $myQuery->flowSQL(); $myQuery->query($query);
or is it even needed to use the second to last line?
Thanks again for your help
Sage
•
•
•
•
I am banging my head against the wall here.
I've tried everything that I can think of to get this to work.
....
in my index page I have the following
PHP Syntax (Toggle Plain Text)
sql = "select * from tablename"; $objAdvertisers = new myData; $objAdvertisers->myStuff($sql);
Using this method keeps giving me an error of
unexpected T_CLASS...
...
PHP Syntax (Toggle Plain Text)
$sql = "select * from tablename"; $objAdvertisers = new myData; $objAdvertisers->myStuff($sql);
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Mar 2008
Posts: 154
Reputation:
Solved Threads: 19
•
•
•
•
The only thing is that I have never seen anything like line 17 before.
is this a PHP5 thing?PHP Syntax (Toggle Plain Text)
function flowSQL($db_server = DATABASE_SERVER, $db_user = DB_USERNAME, $db_pass = DB_PASSWORD, $database = DATABASE)
•
•
•
•
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
PHP Syntax (Toggle Plain Text)
define('DATABASE_SERVER', 'localhost');
•
•
•
•
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.
PHP Syntax (Toggle Plain Text)
// include the configuration file and database class require('include/config.php'); require('include/class/mysql.php');
•
•
•
•
At which point I would be able to do something like
PHP Syntax (Toggle Plain Text)
$query = "SELECT needle FROM haystack WHERE hay = yellow"; $myQuery = new flowSQL; $myQuery->flowSQL(); $myQuery->query($query);
or is it even needed to use the second to last line?
PHP Syntax (Toggle Plain Text)
$dBase = new flowSQL; $query = $dBase->query("SELECT needle FROM haystack WHERE hay = yellow");
We still need to fetch our result however, eg:
PHP Syntax (Toggle Plain Text)
while($result = $dBase->fetch_array($query)) { // do stuff }
Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
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
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
![]() |
Other Threads in the PHP Forum
- Previous Thread: simple, but having a brainfart
- Next Thread: geographical location from IP
Views: 950 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error explodefunction file files folder form forms function functions google hack href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web website xml youtube






