Page 1 of 2

Should beginners to php use PEAR???

Posted: Tue Oct 24, 2006 2:35 pm
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

Posted: Tue Oct 24, 2006 2:39 pm
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.

re

Posted: Tue Oct 24, 2006 2:45 pm
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

)");

Posted: Tue Oct 24, 2006 2:52 pm
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

)");

Posted: Wed Oct 25, 2006 12:43 am
by timvw
and define a primary key..

Posted: Wed Oct 25, 2006 1:09 am
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.

Posted: Wed Oct 25, 2006 3:03 am
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.

Posted: Wed Oct 25, 2006 3:12 am
by s.dot
I've never used pear.

Posted: Wed Oct 25, 2006 4:35 am
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.

re

Posted: Wed Oct 25, 2006 5:35 am
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

Posted: Wed Oct 25, 2006 5:51 am
by timvw
Do you have rights to create a table? What does pear db geterror say after the call?

re

Posted: Wed Oct 25, 2006 8:57 am
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

Posted: Wed Oct 25, 2006 9:43 am
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.

re

Posted: Wed Oct 25, 2006 10:09 am
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

Posted: Wed Oct 25, 2006 10:31 am
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());