Should beginners to php use PEAR???

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

Should beginners to php use PEAR???

Post by ant_sutton »

Hi guys. I'm fairly new to php and have come across the PEAR code packages. I know this makes it easier for programmers when building sites but my question is because I'm quite enw to PHP would it be better for me to learn how to code the funtions myself instead of just linking to PEAR code which I don't understand??

Also, do you professional web developers use PEAR alot or code everything yourself?

thanks alot
Anthony
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

I use PEAR::DB and that's about it.

I say if you understand WHY it helps and understand how to do it the other way, go for it.
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

re

Post by ant_sutton »

Hey. thanks for your reply. I think I will give it a go. Another question: This is the way I'm trying to create a table. I can do it without PEAR easily but this way table isn't being created. ANy ideas?

cheers

Code: Select all

require 'DB.php';

$db = DB::connect('mysql://root@localhost/restaurant');

if (DB::isError($db)) { die("Can't connect: " . $db->getMessage( )); }


$q = $db->query("CREATE TABLE dishes (

        dish_id INT,

        dish_name VARCHAR(255),

        price DECIMAL(4,2),

        is_spicy INT

)");
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Try changing the following:

Code: Select all

$q = $db->query("CREATE TABLE dishes (

        dish_id INT,

        dish_name VARCHAR(255),

        price DECIMAL(4,2),

        is_spicy INT

)");
To:

Code: Select all

$db->query("CREATE TABLE dishes (

        dish_id INT,

        dish_name VARCHAR(255),

        price DECIMAL(4,2),

        is_spicy INT

)");
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

and define a primary key..
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

The only Pear package I use frequently is HTML_QuickForm, and I am pretty happy with it... it's far from perfect, but it's definately better than any other form library I've come across. One nice thing I can say about PEAR is that its installer couldn't be any easier.

There's no problem with using libraries/packages... a lot of time, in the real world there are deadlines and you have no choice but to use them.. it just makes sense. I'm sure you've heard the saying "Why re-invent the wheel?"

The longer you code though, the more you will find yourself stretching the limits of the libraries, and beginning to see their pitfalls as well... but by that time you'll be a pro and have a stockpile of your own code all over your hard drive.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

I would first learn without PEAR especially since everyone does not use PEAR and many use other Frameworks. If you know plain PHP then picking up any of the Frameworks is pretty easy.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I've never used pear.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I've only ever used the PEAR benchmarking class for timing code execution, and only because it was advised in a book I read.
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

re

Post by ant_sutton »

Hi guys. thanks so much for your responses, great help. I think I've decided to learn php a bit more before trying to use PEAR since it's oviously not strictly necessary at this point if some of you rarely use it. But I do realise the benefits of it. I've also decided this as I still can't seem to create a simple table using pear anyway :) I've added a primary key and chnaged the code that the guy with the weird user name suggested but I still can't get it to create the table.

ANy more ideas on why this is happening will be much appreciated. thanks alot
Anthony
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Do you have rights to create a table? What does pear db geterror say after the call?
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

re

Post by ant_sutton »

Hi tim. thanks for your reply.

I'm sure I have all privileges to make a table. I can do it using the same user and password wihtout pear. the get error doesn't return any error message. I run the script and the page is just blank as it should be but the table doesn't get created

cheers
Anthony
dranger
Forum Newbie
Posts: 6
Joined: Thu Sep 07, 2006 1:46 am

Post by dranger »

ant_sutton wrote:

Code: Select all

$q = $db->query("CREATE TABLE dishes (

        dish_id INT,

        dish_name VARCHAR(255),

        price DECIMAL(4,2),

        is_spicy INT

)");
Try checking if $q is an error -

Code: Select all

if(DB::isError($q)) { die("Error in query: " . $q->getMessage( )); }
(basically copy the code you use to check the db connect for errors)
Assigning the result of $db->query to $q has no effect on whether the table is created or not.
ant_sutton
Forum Commoner
Posts: 32
Joined: Thu May 05, 2005 5:27 am

re

Post by ant_sutton »

Hi dranger. thanks for the code. I added it but still no error s returned. just a blank page. I'mreally not sure waht that means. I'ts getting really annoying now.

cheers

Anthony
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I've got the feeling that errors aren't output... So i would suggest to use echo $q->GetMessage(); instead of die($q->GetMessage());
Post Reply