|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
I don't understand what this code does:
PHP Code:
Thanks, -Corbb |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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? |
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Article Discussion: PHP and Databases for the Lazy Sod |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|