Re: PHP database syntax/construct: can we make it better?

From: Date: Tue, 11 Jul 2000 21:16:55 +0000
Subject: Re: PHP database syntax/construct: can we make it better?
Groups: php.general 
Request: Send a blank email to php-general+get-6013@lists.php.net to get a copy of this message
Well, what you've described below reminds me a lot of Pervasive's Tango 2000. It is meta-tag based as opposed to scripting. <@rows array="local$resultset"> <tr> <td><@col 1></td> <td><@col 2></td> </tr> </@rows> That would loop through a DB result. I do agree that it is a bit easier to work with than the C-like approache. But there gets to a point where scripting is better than this Meta tag approach. I have grown to hate the meta tagness of languages like Pervasive's Tango. I think a lot of the "simplicity" that you want could be achieved if you created a db class that fit your needs. I'm working on one for myself that I use on all my sites. It goes like this: $sql = new dbODBC("user","pass","db"); $sql->query("SELECT * FROM table"); while ($sql->getRow()) { echo $sql->getColumn("column_name"); } echo $sql->getNumRows() . " rows were found."; I also am building stuff like friendly quote checking, etc into the class to eliminate the tedious stuff. My db class is abstract, so it could be used with any db, although currently I only have ODBC and MySQL implemented. I find that using a wrapper class with PHP makes it as easy to use as the mega tag based approach, and yet much more powerful. -- Matthew Leverton - matthew@aeroinc.net - http://www.allegro.cc -----Original Message----- From: Monte Ohrt <monte@ispi.net> To: php-general@lists.php.net <php-general@lists.php.net>; php-dev@lists.php.net <php-dev@lists.php.net> Date: Tuesday, July 11, 2000 4:00 PM Subject: [PHP] PHP database syntax/construct: can we make it better? >One thing about PHP that has always been kind of difficult is the way it >accesses databases. I'm not necessarily talking about abstraction, but >the way the syntax works which is mostly inherited from the PHP language >structure. > >Here is an example of what I mean. I'll give one example of how PHP does >a database query, and then a comparison to the way another "html-ish" >scripting language accomplishes the same task. > >Example: selecting and displaying rows from a database. > >---PHP:--- > ><? > > $link = mysql_connect("my_host","my_name","my_pass"); > mysql_select_db("my_db",$link); > > $result = mysql_query("select first,last,addr from my_table",$link); > > while($row = mysql_fetch_row($result) { > printf("%s, %s, %s<br>\n",$row[0],$row[1],$row[2]); > } > > echo "there were ".mysql_num_rows($result)." records found.<br>\n"; > >?> > > >---OTHER HTML-TYPE LANGUAGE:--- > > ><HOST = "my_host"> ><USER = "my_name"> ><PASS = "my_pass"> ><DB = "my_db"> > ><SQL "select first,last,addr from my_table"> > $first, $last, $addr<br> ></SQL> >There were $loop records found. > > > > >Of course each syntax has it's pros and cons. PHP is much more >extensible, but the latter is quite easy to read and quick to implement >without the need to construct for() and while() loops. Is there any way >to make PHP a bit easier to work with, instead of constantly having to >create while loops, calling functions for simple things like number of >rows fetched, etc.? Any good way to implicitly automate this? > >I have some ideas, but they require modifying the fundamental PHP >language construct. > >I have attached those thoughts below. Any other ideas, or do we just >deal with what we have? > >Monte

« previous php.general (#6013) next »