php-general Digest 2 May 2011 20:57:48 -0000 Issue 7294

Topics (messages 312619 through 312635):

Re: postgresql database access failure
        312619 by: e-letter
        312620 by: Tim Streater
        312631 by: Matt Graham

Re: passing control to a separate script
        312621 by: Jim Giner
        312622 by: Jim Giner
        312623 by: Stuart Dallas
        312624 by: tedd
        312625 by: Tim Streater
        312626 by: Stuart Dallas

make links
        312627 by: Michael Simiyu
        312628 by: Adam Preece

what would be the best way to build a 'add page function' to my cms?
        312629 by: Adam Preece
        312630 by: Ashley Sheridan
        312632 by: Adam Preece
        312633 by: Ashley Sheridan
        312634 by: Adam Preece

semaphore release before acquire warning
        312635 by: Jeremy Greene

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
>
>Here's the URL of the relevant manual page:
>http://www.php.net/manual/en/function.pg-fetch-result.php
>

The manual page did not explain the purpose of the text 'die', so was
ignored (;)). Anyway, the php code was amended as follows:

        <?php
                $db = pg_connect('dbname=databasename user=httpd');
                $query = pg_query($db,'SELECT * FROM databasetable');
                $value=pg_fetch_result($query,100,0);
                echo 'list of files' ,$value,'\n';
        ?>

The result is a web page which shows:

list of files12345\n

where '12345' corresponds correctly to an equivalent value in row 100
of the database table. However, the query requests the entire table.

The php code was then amended as follows, which produces output from
the database:

        <?php
                $db = pg_connect('dbname=databasename user=httpd');
                $query = pg_query($db,'SELECT * FROM databasetable');
                $value=pg_fetch_all_columns($query,1);
                var_dump($value);
        ?>

>My personal recommendation, however, is to drop old-style procedural
>drivers and switch to PDO - it's much more convenient to use, IMO. If
>you use PDO, you don't need to study the API of various different DB
>drivers, and your code can easily switch from one database to another.

What does PDO mean, so the relevant parts of the manual can be
reviewed? Thank you.

--- End Message ---
--- Begin Message ---
On 02 May 2011 at 11:05, e-letter <[email protected]> wrote: 

>>
>> Here's the URL of the relevant manual page:
>> http://www.php.net/manual/en/function.pg-fetch-result.php
>>
>
> The manual page did not explain the purpose of the text 'die', so was
> ignored (;)).

What, you mean this?

     $db = pg_connect("dbname=users user=me") || die();

It's what I would call an ugly and unreadable way of handing errors. Personally 
I'd do this:

     $db = pg_connect("dbname=users user=me");
     if  ($db===false)
          {
          // Do any error handling (such as writing to my log file) here
          die ();
          }

And which manual page are you talking about? die() is a function so it's 
trivial to search for it in the functions list using the search facility on all 
PHP documentation pages.

> Anyway, the php code was amended as follows:
>
>       <?php
>               $db = pg_connect('dbname=databasename user=httpd');
>               $query = pg_query($db,'SELECT * FROM databasetable');
>               $value=pg_fetch_result($query,100,0);
>               echo 'list of files' ,$value,'\n';
>       ?>
>
> The result is a web page which shows:
>
> list of files12345\n
>
> where '12345' corresponds correctly to an equivalent value in row 100
> of the database table. However, the query requests the entire table.
>
> The php code was then amended as follows, which produces output from
> the database:
>
>       <?php
>               $db = pg_connect('dbname=databasename user=httpd');
>               $query = pg_query($db,'SELECT * FROM databasetable');
>               $value=pg_fetch_all_columns($query,1);
>               var_dump($value);
>       ?>
>
>> My personal recommendation, however, is to drop old-style procedural
>> drivers and switch to PDO - it's much more convenient to use, IMO. If
>> you use PDO, you don't need to study the API of various different DB
>> drivers, and your code can easily switch from one database to another.
>
> What does PDO mean, so the relevant parts of the manual can be
> reviewed? Thank you.

Go to the PHP Manual front page, scroll down to Database Extensions under 
Function Reference.

I think you need to learn to find stuff for yourself in the manual. Finding 
PDO, die(), and pg_query (which you initially missed altogether) should be easy 
enough.


--- End Message ---
--- Begin Message ---
Florin Jurcovici wrote:
> My personal recommendation, however, is to drop old-style procedural
> drivers and switch to PDO - it's much more convenient to use, IMO.

Just be careful.  PDO's implementation of MySQL doesn't implement the
mysql_set_charset() function, or at least it didn't a while back according to
my reading the PDO source.  Setting a charset in the DSN was possible, but PDO
didn't *do* anything with that setting.  There are probably other minor holes
out there.  ("Everything in these tables is UTF-8!"  "Are you *sure* about
that?  It looks a lot like CP-1252 here, and here, and here....")

> you use PDO, you don't need to study the API of various different DB
> drivers, and your code can easily switch from one database to another.

This is true to some extent.  There are probably a few odd cases where the
native functions do more, or do it better than whatever the latest and
greatest layer of abstraction does.

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see


--- End Message ---
--- Begin Message ---
No includes.  Period.
> To get "script 1 to begin" from script 2 based on a certain path...
>
> script2.php
> ---
> if ($path1)
> {
> // do stuff here
> include('script1.php');
> exit;
> }
> // otherwise do other stuff here
> ---
>
> -Stuart
>
> -- 
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
>
>
>
> 



--- End Message ---
--- Begin Message ---
Sorry - I responded directly to the responder - BECAUSE - I lost track of 
who I was answering.  That's what happens when people choose to repond to 
the poster directly INSTEAD of JUST replying to the list.

Tedd gave me the 'header' directive and it works just as I imagined 
something would do.  See below.

>>Is this do-able?
>
> Yes, this is do-able.
>
>
> If you don't want to use a $_POST to trigger the critter, then use 
> location, such as:
>
> // first script
> if($to_second_script)
>   {
>    header('Location: http://www.example.com/second.php');
>    exit();
>    }
>
> // second script
> if($to_first_script)
>   {
>    header('Location: http://www.example.com/first.php');
>    exit();
>    }
>
>
> Either those will work depending upon the trigger you need.
>
> Cheers,
>
> tedd
>
> -- 
> -------
> http://sperling.com/ 



--- End Message ---
--- Begin Message ---
I don't understand what you have against includes. Redirecting the browser as 
tedd suggested will work but it's a waste of resources to bounce the request 
off the client unless you have a good reason for doing so (eg. changing the URL 
the browser is showing or preventing reloads htting the initial script again). 
If either of those are your goal then it would have been helpful for you to say 
so.

If not, why are you so against using includes?

-Stuart

Sent from my leaf blower

On 2 May 2011, at 13:55, "Jim Giner" <[email protected]> wrote:

> Sorry - I responded directly to the responder - BECAUSE - I lost track of 
> who I was answering.  That's what happens when people choose to repond to 
> the poster directly INSTEAD of JUST replying to the list.
> 
> Tedd gave me the 'header' directive and it works just as I imagined 
> something would do.  See below.
> 
>>> Is this do-able?
>> 
>> Yes, this is do-able.
>> 
>> 
>> If you don't want to use a $_POST to trigger the critter, then use 
>> location, such as:
>> 
>> // first script
>> if($to_second_script)
>>  {
>>   header('Location: http://www.example.com/second.php');
>>   exit();
>>   }
>> 
>> // second script
>> if($to_first_script)
>>  {
>>   header('Location: http://www.example.com/first.php');
>>   exit();
>>   }
>> 
>> 
>> Either those will work depending upon the trigger you need.
>> 
>> Cheers,
>> 
>> tedd
>> 
>> -- 
>> -------
>> http://sperling.com/ 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
At 2:48 PM +0100 5/2/11, Stuart Dallas wrote:
Sent from my leaf blower

Leaf blower?

I suppose some day soon, we will send stuff from our watches. From a leaf blower would be pushing technologies invasion into our personal lives a bit much -- but I guess that's your point.

Cheers,

tedd

--
-------
http://sperling.com/

--- End Message ---
--- Begin Message ---
On 02 May 2011 at 15:40, tedd <[email protected]> wrote: 

>> At 2:48 PM +0100 5/2/11, Stuart Dallas wrote:
>> Sent from my leaf blower
>
> Leaf blower?
>
> I suppose some day soon, we will send stuff from our watches. From a
> leaf blower would be pushing technologies invasion into our personal
> lives a bit much -- but I guess that's your point.

I'd say he was expressing annoyance at these mails saying "sent from my 
raspberry", as if somehow anyone gives a monkey's.

tim


--- End Message ---
--- Begin Message ---
On Monday, 2 May 2011 at 17:23, Tim Streater wrote:
On 02 May 2011 at 15:40, tedd <[email protected]> wrote: 
> 
> > > At 2:48 PM +0100 5/2/11, Stuart Dallas wrote:
> > > Sent from my leaf blower
> > 
> > Leaf blower?
> > 
> > I suppose some day soon, we will send stuff from our watches. From a
> > leaf blower would be pushing technologies invasion into our personal
> > lives a bit much -- but I guess that's your point.
> 
> I'd say he was expressing annoyance at these mails saying "sent from my 
> raspberry", as if somehow anyone gives a monkey's.

It's not annoyance - I couldn't care less what people put in their sigs, or 
what device they're using to send emails. My phone has had that sig since the 
iPhone was released because I find it amusing that so many people leave that 
default in place. I used to wonder why they didn't change it, but now I just 
don't care. I'm happy with my leaf blower - it serves me well, but that's no 
reason to shout about which leaf blower it is.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/





--- End Message ---
--- Begin Message ---
hello,

i want to add links to the code below in wordpress ie where it says "control the world" and "read and comment only" i want to make it a link <a href="http://www.google.com"; target="_self">My Link</a>

<?php
if (current_user_can('level_10')) : ?>
<?php print "control the world"; ?>
<?php elseif (current_user_can('level_6')) : ?>
<?php print "read and comment only"; ?>
<?php else : ?>
<?php print "you gotta log-in to see the goodies"; ?>
<?php endif; ?>

Thanks

--- End Message ---
--- Begin Message ---
hi, then use this.

> <?php
> if (current_user_can('level_10')) : ?>
> <?php print "<a href=\"http://www.google.com\"; target=\"_self\">My Link</a>"; 
> ?>
> <?php elseif (current_user_can('level_6')) : ?>
> <?php print "read and comment only"; ?>
> <?php else : ?>
> <?php print "you gotta log-in to see the goodies"; ?>
> <?php endif; ?>

hope this helps

Adam
On 2 May 2011, at 17:49, Michael Simiyu wrote:

> hello,
> 
> i want to add links to the code below in wordpress ie where it says "control 
> the world" and "read and comment only" i want to make it a link <a 
> href="http://www.google.com"; target="_self">My Link</a>
> 
> <?php
> if (current_user_can('level_10')) : ?>
> <?php print "control the world"; ?>
> <?php elseif (current_user_can('level_6')) : ?>
> <?php print "read and comment only"; ?>
> <?php else : ?>
> <?php print "you gotta log-in to see the goodies"; ?>
> <?php endif; ?>
> 
> Thanks
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--- End Message ---
--- Begin Message ---
Hi,

im building a cms and im currently thinking of a way to build an add page 
function.

any one got some ideas on the best way to achieve this?

cheers

--- End Message ---
--- Begin Message ---
On Mon, 2011-05-02 at 17:59 +0100, Adam Preece wrote:

> Hi,
> 
> im building a cms and im currently thinking of a way to build an add page 
> function.
> 
> any one got some ideas on the best way to achieve this?
> 
> cheers



That's a bit of an open question, and there are several things that need
to be answered first:


      * Is each page a standalone one based on a template that just
        allows the main content to be changed?
      * Is a page made up of several snippets?
      * Does the CMS save out the final HTML page, or does it store just
        the content in a DB to insert into a page at runtime when
        requested?


A CMS can be a pretty big build, and needs a lot of thought to get
right. It depends on your requirements and who it's going to be used by.
~Are you able to be a bit more specific about your question so we can be
more specific with our answers?

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi,

sure i will try to be more specific.

> Is each page a standalone one based on a template that just allows the main 
> content to be changed?
yes.

> Is a page made up of several snippets?
could be, depends on what has to be done.

> Does the CMS save out the final HTML page, or does it store just the content 
> in a DB to insert into a page at runtime when requested?
and it will just store the content in the db and insert into page at runtime 
when requested.



the overall system i would like to achieve, is a simple, clean, CRUD , manage 
users, set user access (admin, super_user etc), add pages, newsletter 
functionality, latest news, and anything else that might be nice to create for 
it.

my target audience, are people who are not coders, just people that would like 
to manage there content with ease.

oh and i'm trying to build it all in OOP too.

hope this is a better explanation for you guys.

cheers



On 2 May 2011, at 18:12, Ashley Sheridan wrote:

> On Mon, 2011-05-02 at 17:59 +0100, Adam Preece wrote:
>> 
>> Hi,
>> 
>> im building a cms and im currently thinking of a way to build an add page 
>> function.
>> 
>> any one got some ideas on the best way to achieve this?
>> 
>> cheers
> 
> 
> That's a bit of an open question, and there are several things that need to 
> be answered first:
> 
> Is each page a standalone one based on a template that just allows the main 
> content to be changed?
> Is a page made up of several snippets?
> Does the CMS save out the final HTML page, or does it store just the content 
> in a DB to insert into a page at runtime when requested?
> 
> A CMS can be a pretty big build, and needs a lot of thought to get right. It 
> depends on your requirements and who it's going to be used by. ~Are you able 
> to be a bit more specific about your question so we can be more specific with 
> our answers?
> 
> -- 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


--- End Message ---
--- Begin Message ---
On Mon, 2011-05-02 at 18:43 +0100, Adam Preece wrote:

> Hi,
> 
> sure i will try to be more specific.
> 
> > Is each page a standalone one based on a template that just allows the main 
> > content to be changed?
> yes.
> 
> > Is a page made up of several snippets?
> could be, depends on what has to be done.
> 
> > Does the CMS save out the final HTML page, or does it store just the 
> > content in a DB to insert into a page at runtime when requested?
> and it will just store the content in the db and insert into page at runtime 
> when requested.
> 
> 
> 
> the overall system i would like to achieve, is a simple, clean, CRUD , manage 
> users, set user access (admin, super_user etc), add pages, newsletter 
> functionality, latest news, and anything else that might be nice to create 
> for it.
> 
> my target audience, are people who are not coders, just people that would 
> like to manage there content with ease.
> 
> oh and i'm trying to build it all in OOP too.
> 
> hope this is a better explanation for you guys.
> 
> cheers
> 
> 
> 
> On 2 May 2011, at 18:12, Ashley Sheridan wrote:
> 
> > On Mon, 2011-05-02 at 17:59 +0100, Adam Preece wrote:
> >> 
> >> Hi,
> >> 
> >> im building a cms and im currently thinking of a way to build an add page 
> >> function.
> >> 
> >> any one got some ideas on the best way to achieve this?
> >> 
> >> cheers
> > 
> > 
> > That's a bit of an open question, and there are several things that need to 
> > be answered first:
> > 
> > Is each page a standalone one based on a template that just allows the main 
> > content to be changed?
> > Is a page made up of several snippets?
> > Does the CMS save out the final HTML page, or does it store just the 
> > content in a DB to insert into a page at runtime when requested?
> > 
> > A CMS can be a pretty big build, and needs a lot of thought to get right. 
> > It depends on your requirements and who it's going to be used by. ~Are you 
> > able to be a bit more specific about your question so we can be more 
> > specific with our answers?
> > 
> > -- 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> 


Well, that's essentially still pretty vague, as those are generally the
requirements of most CMS's out there. What's wrong with using an
existing system and building upon that? Something like WordPress is
pretty user friendly and easy to code for. If you're asking a list about
how to add a page, then it suggests that maybe this project is too big
for you alone. I don't mean that in any disparaging way, but these
systems are deceptively complex.

What about a simple template-type system with each page using a template
of modules. A module could be something like a simple static article, or
more complex, like a gallery. Each template defines the type of content
that appears on it. When adding a new page, select from a template and
it pulls in the various modules as required to build a page.

It might be worth looking at a lot of existing systems and see how they
tackle the issue, as each one takes a slightly different approach, and
it could be that one is closer than the others to what you want and you
can use the general idea to build your own.


-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
the reason, why i don't want to use word press and any other open source 
solution, is that i want to learn how it is all done. im sure i can figure it 
out myself but i would like to ask others and see how they would tackle it.

the idea with the modules sounds really cool, template type system.

if you have the time could you please tell me more how i could achieve a 
modular template system?

cheers

On 2 May 2011, at 18:52, Ashley Sheridan wrote:

> On Mon, 2011-05-02 at 18:43 +0100, Adam Preece wrote:
>> 
>> Hi,
>> 
>> sure i will try to be more specific.
>> 
>> > Is each page a standalone one based on a template that just allows the 
>> > main content to be changed?
>> yes.
>> 
>> > Is a page made up of several snippets?
>> could be, depends on what has to be done.
>> 
>> > Does the CMS save out the final HTML page, or does it store just the 
>> > content in a DB to insert into a page at runtime when requested?
>> and it will just store the content in the db and insert into page at runtime 
>> when requested.
>> 
>> 
>> 
>> the overall system i would like to achieve, is a simple, clean, CRUD , 
>> manage users, set user access (admin, super_user etc), add pages, newsletter 
>> functionality, latest news, and anything else that might be nice to create 
>> for it.
>> 
>> my target audience, are people who are not coders, just people that would 
>> like to manage there content with ease.
>> 
>> oh and i'm trying to build it all in OOP too.
>> 
>> hope this is a better explanation for you guys.
>> 
>> cheers
>> 
>> 
>> 
>> On 2 May 2011, at 18:12, Ashley Sheridan wrote:
>> 
>> > On Mon, 2011-05-02 at 17:59 +0100, Adam Preece wrote:
>> >> 
>> >> Hi,
>> >> 
>> >> im building a cms and im currently thinking of a way to build an add page 
>> >> function.
>> >> 
>> >> any one got some ideas on the best way to achieve this?
>> >> 
>> >> cheers
>> > 
>> > 
>> > That's a bit of an open question, and there are several things that need 
>> > to be answered first:
>> > 
>> > Is each page a standalone one based on a template that just allows the 
>> > main content to be changed?
>> > Is a page made up of several snippets?
>> > Does the CMS save out the final HTML page, or does it store just the 
>> > content in a DB to insert into a page at runtime when requested?
>> > 
>> > A CMS can be a pretty big build, and needs a lot of thought to get right. 
>> > It depends on your requirements and who it's going to be used by. ~Are you 
>> > able to be a bit more specific about your question so we can be more 
>> > specific with our answers?
>> > 
>> > -- 
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> > 
>> > 
>> 
> 
> Well, that's essentially still pretty vague, as those are generally the 
> requirements of most CMS's out there. What's wrong with using an existing 
> system and building upon that? Something like WordPress is pretty user 
> friendly and easy to code for. If you're asking a list about how to add a 
> page, then it suggests that maybe this project is too big for you alone. I 
> don't mean that in any disparaging way, but these systems are deceptively 
> complex.
> 
> What about a simple template-type system with each page using a template of 
> modules. A module could be something like a simple static article, or more 
> complex, like a gallery. Each template defines the type of content that 
> appears on it. When adding a new page, select from a template and it pulls in 
> the various modules as required to build a page.
> 
> It might be worth looking at a lot of existing systems and see how they 
> tackle the issue, as each one takes a slightly different approach, and it 
> could be that one is closer than the others to what you want and you can use 
> the general idea to build your own.
> 
> 
> -- 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


--- End Message ---
--- Begin Message ---
Hi,

 

I am getting a warning when calling sem_release() before (the same php
script) calls sem_acquire(). I am doing this because it's a "signal" to
another process. The other process (which happens to be C program) has
done, or will do, a semop() to acquire the semaphore/signal. The actual
data transfer is through shared memory.

 

It does all functionally work quite nicely, but given that I'm getting
the warning and that there doesn't seem to be any discussion of this at
least in this list's archive maybe I'm putting a square peg into a round
hole... or at least there's a rounder peg available.

 

I did look into disabling the warning, but that got me more concerned
since it seemed like a frowned upon thing to do and even more of a
performance hit.

 

The irony is that I'm using shared memory (and signals) exactly for
performance reasons L

 

Jeremy

 

 


--- End Message ---

Reply via email to