Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 20th, 2003, 12:12 AM
Vantera Vantera is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: South Coast of NSW, Australia
Posts: 108 Vantera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Vantera
Article Discussion: PHP and Databases for the Lazy Sod

PHP and Databases for the Lazy Sod If you have any questions or comments about this article please post them here.

You can read the article here .
__________________
Kind Regards,
John Rebbeck
john@interspire.com
ICQ# 74637937

Reply With Quote
  #2  
Old January 20th, 2003, 12:23 PM
WebGuy WebGuy is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 54 WebGuy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I don't understand what this code does:
PHP Code:
<?php 

include_once "ez_sql.php"

$users $db->get_results("SELECT * FROM users"); 

foreach ( 
$users as $user 

  echo 
$user->name


?>
What does the foreach ( $users as $user ) do? Are those just variables I make up?

Thanks,
-Corbb
__________________
Sincerely,
Corbb O'Connor, Author at DevArticles

Reply With Quote
  #3  
Old January 20th, 2003, 06:33 PM
Vantera Vantera is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: South Coast of NSW, Australia
Posts: 108 Vantera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Vantera
WebGuy: I am not a PHP programmer but this is a common technique in quite a lot of languages.

I'll try to explain.

The variable $users contains a collection of users as a recordset/array that was retrieved from $db->get_results.
What the foreach statement is iterate each of the users in $users and on each loop it assigns the current user (from $users) to $user so it can be accessed easily.

I hope I explained that well.

Reply With Quote
  #4  
Old January 21st, 2003, 11:16 AM
jv22 jv22 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 17 jv22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I will try and explain this bit by bit.

$users = $db->get_results("SELECT * FROM users");
This line explained.. bit by bit....

$db->get_results
a function that gets results from the database

SELECT * FROM users
the query issued to the database

$users =
create a new array called $users and put any values from $db->get_results into it

-------

foreach ( $users as $user )
{
echo $user->name;
}


And now this bit explained bit by bit...

foreach ( $users
take the array that we just created step through it.

as $user )
within the brackets we can get a handle on the data by using the name specifed here. Here is the same thing with names that are easier to understand..

foreach ( $bit_of_this_array as $one_row )
{
echo $one_row;
}

it is the same as doing....

for ( $i=0; $my_array[$i] != NULL; $i++ )
{
echo $my_array[$i];
}

but it is easier..

Cheers,
Justin

Reply With Quote
  #5  
Old January 30th, 2003, 04:11 AM
Ezudin Ezudin is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Sarajevo, B&H
Posts: 2 Ezudin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Error checking in ezSql query

What is the way for error checking in ezSql query?

For example, using native mysql we have:

$sql = "UPDATE articles SET .... WHERE id=$id";

if ( mysql_query($sql) ) {
echo("<h1>Data succesfully changed</h1>");
} else {
echo("<P>Error...: " . mysql_error() . "</P>");
}
-----
With ezSql:

if ($db->query($sql) ) {....

doesn't work;


Then I tried:

$db->query($sql);

if ( !$EZSQL_ERROR ) {
echo("<h1>Data succesfully changed</h1>");
}else {
echo("<P>Error...</P>");
$db->vardump($EZSQL_ERROR);
}

and this work!

Any suggestion welcome.

Reply With Quote
  #6  
Old January 30th, 2003, 05:46 AM
jv22 jv22 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 17 jv22 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ezudin,

Good point.

I have updated ezSQL so that it now does
as you have suggested. Please get the latest version
from http://php.justinvincent.com

Cheers,
Justin

Reply With Quote
  #7  
Old February 14th, 2003, 03:52 PM
binggeli binggeli is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 1 binggeli User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Why does WHERE condition1 AND condition2 not work?

First off, I love being a lazy sod with this kind of code. Awesome.

Although I have done some work in PHP and MySQL, I don't quite understand why I can't use a statement like this:


$user = $db->get_row("SELECT * FROM subscribers WHERE subscriber_uid = '$uid' AND subscriber_pwd = password('$pwd')");


As long as I use one WHERE condition at a time, I'm fine and everything works.

I also saw the user name/password example, but that wouldn't work for me, since the passwords are encrypted using MySQL's "password" function.

Additionally, I have tried get_results, but that didn't seem to work either.

Any ideas? Anyone?

Reply With Quote
  #8  
Old February 19th, 2003, 05:04 PM
joekeenan joekeenan is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Belfast, Ireland
Posts: 1 joekeenan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using PHP 4.1.2 on a remote host (Zeus server software) and there doesn't seem to be anything odd about the configuration (as per phpinfo). EZSQL is fine on queries where the database is modified, insert and update, and no result displayed. However, with the examples given, none of those where results were to be displayed, worked. All produced a parse error message citing the line where echo() is called or other function requiring results to be displayed.
I set up a table "users" in mysql with 3 fields for id, name and email. The scripts were simply the include ezsql line and the code given. I'm sure I'm missing something very simple. But am too simple to know what it is. Any help on this much appreciated.

Reply With Quote
  #9  
Old April 8th, 2003, 08:27 PM
DasGnu DasGnu is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Germany
Posts: 1 DasGnu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

ezSQL is a really good class.
But is it possible to show all DEBUG-Outputs in a "Popup"-window ?

Last edited by DasGnu : April 8th, 2003 at 08:30 PM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Discussion: PHP and Databases for the Lazy Sod


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT