[PHP] simpleXML - can't add children - why? - stuck
Hello all, I'm struggling here, but no joy so far. Having this XML file that I'm loading using simplexml_load_file(): http://pastebin.com/JiW3LxWM I need to add some domain:create children nodes after line 8. What do I need to add? This: http://pastebin.com/mT27g3ZN In order to do so, I have used the following php snipped: http://pastebin.com/a1gG8tXx I'm getting this warning and, after it, a fatal error: Warning: SimpleXMLElement::addChild() [simplexmlelement.addchild]: Cannot add child. Parent is not a permanent member of the XML tree. (line number 1 of last paste bin) Fatal error: Call to a member function addChild() on a non-object (line number 2 of last paste bin) Note that: The constant used is correct. The php version is higher then 5.1. On the same command, later on this code, I was able to create child nodes with no issues. I'm far (veery far) from being a guru, so please, what can I do to debug this, and find out what's going on? Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Migration Scheme - from one mysql DB to another mysql DB
Hello all, If possible, I would like to ask and have your help about the methods and procedures that should exist to accomplish the following task: I need to grab some data from one mySQL database with some specific table and field names, to another mySQL database with specific table and field names. The destination database tables are empty. What is a common procedure to do on those cases? Is there any? Several? What are the most common? If I need to be more specific in order to benefit from your help, please, let me know. Best regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Migration Scheme - from one mysql DB to another mysql DB
I'd like to know - what type of hosting and OS the 2 databases are running. - if they're (staying) on the same machine, and if not: whats the available bandwith (updown, lowpeak) between the machines? any cost to that bandwith? - if you have admin rights on both databases. - how often you need to do this and for how much data (in Mb) Thank you all for your replies. I will leave you with more details, but, I believe the single query approach with two PDO (or mysqli) connections should be quite well. Both DB are on the same server, Linux based one, but different dsn should apply. The bandwith cost will not be an issue, because we are talking about 15MB of data, or something similar. I don't have admin rights but I can try to have them if I must to. I believe this will be a single time, or, one in a long time run but, we can never predict. The destination table also has some random data filled fields that I need to generate and introduce with the old data on this new database. Wondering if mySQL Migration Toolkit can do the job? Thanks a lot for your help, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] headers help
Hello all, I must confess I know the very basics on this language and have even less knowledge about http headers. I wish you could help me out on this: I have a form that sends html e-mails and an optional file as attachment. The issue is that, if the file is NOT send, the e-mail receives two times the same content, one that gets read by the mail clients as HTML properly, and, a literal print of my $message string variable that contains: html head /head boby tableMy form contents/table /body /html I believe that the reason for this lies on the $header options, probably on line number 8 ? Here is the, what I believe, is the relevant code: http://pastebin.com/5ywdK0UU What should I do, to avoid this extra html code on the e-mail messages ? Thanks in advance, Márcio
[PHP] RE: headers help
I've had a quick look and this: http://pastebin.com/RswEBPLd may work; if not though you want to view the source of an email from anywhere which displays correctly; and the source of one from your application - then compare to get the fix :) Regards! Thanks Nathan, I will give it a try. Mime headers is what I should look for, ok. :) I found weird having more than 1 content-type defined, and more than one decoding method defined as well. I will do my part and try the code you give, try to understand the changes, do some testing, and now, search MIME Headers. Maybe the issue could also lie on conditional placement/logic parts, here the block code in the complete context: http://pastebin.com/NjC1C3U9 Best Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow
-Original Message- From: MEM [mailto:tal...@gmail.com] Sent: terça-feira, 27 de Outubro de 2009 12:05 To: 'a...@ashleysheridan.co.uk' Cc: 'Jim Lucas'; 'php-general@lists.php.net' Subject: RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow Think of it a bit like an online shop selling operating systems: 1) All the main OS's you sell are on the front page - Linux, MacOS Windows 2) User clicks on Linux, and is taken to the url /products/linux and they are shown all the Linux OS's on offer (Fedora, SuSe, Ubuntu, Knoppix, etc) 3) User clicks on Fedora and is taken to the URL /products/linux/fedora and they are shown all the versions of Fedora up to 11 4) etc The URL belies what section you are on, which makes it easy for the user to remember, and easy for you to extract information from to know exactly where the user is. Obviously in the above URLs I'm assuming mod_rewrite is being used. Thanks, Ash http://www.ashleysheridan.co.uk Thanks a lot! Really. I will now start coding based on all this information and see what I will get. I'm sure that the designer will kill me later, by telling me... couldn't we just... fade in this a little bit... Ahhrrggg!!! Regards, Márcio Hello once again, I have take my time to think on this for a while. And I end up on the W3C recommendations about URIs: In a phrase: Keep it semantic, lifetime, and short. Several questions arise at this moment: I was having a url like this: http://www.mysite.com/c_mycontroller/method/1/3/4/54 Where the numbers where Id's of categories or products. Well... this could be as far as we can get from the W3C recommendations. :s So, let's say I short those urls to names, and I remove/hide(?) from the URL the controller and method information's. We could end up on something like this: http://www.mysite.com/categoryname/subcategoryname/subsubcategoryname/productname/ It's more semantic. But what if we have, 4 subcategories for example? This could get quite long. A possible solution to this, is to have something like this: http://www.mysite.com/categoryname/subcategoryname/productname In a way that we always get no more than 3 URI segments. So, if the user navigates to a sub sub sub sub level on the hierarchy, the address could be: http://www.mysite.com/categoryname/subsubsubsubcategoryname/productname 1) What are your thoughts on this? Should I follow this track on your opinions? 2) In order to be semantic, I intend to pass through the URI segments, NOT the Category id's but the Category names. This will bring two issues (at least): 2.1) - I need to query the database, not by ID but by Name. (I'm not sure if they always be unique, I'm not sure if I will have a performance issue). As a note: This is a VERY little website. Nothing too fancy. 2.2) I will grab the categories name from the database, and build the URL with those names, however, some category names will have INVALID chars, like á, ç, spaces... etc... What would be the best way of doing this? Having a new column on the database categories table with a slug field? Or, grab the category name, and prepare that name to be url friendy using a function for that? If it's possible to answer, where on a MVC structure would this function be? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with my first recursion menu
Hello all, Please have a look here: http://www.nuvemk.com/c_categoria/seccao/1 When we click on Fitofármacos, I can display the correspondent children! This is great! And I'm really happy! :) When we click on Fitofármacos children - Herbicidas, I was expecting to have returned Herbicidas childs, without losing the Fitofármacos menu item. The reason I'm losing him, I suppose, it's due the fact that the URI is not properly generated by the function responsible to parse a menu. Notice that, on the link posted above: If you click on fitofármacos and then click on herbicidas, the expected URL should be: http://www.nuvemk.com/c_categoria/seccao/1/6/9/ but I'm getting this instead: http://www.nuvemk.com/c_categoria/seccao/6/9/ If we try to navigate deeply, and inside Herbicidas we click on Herbicidas A, we are expecting an URL like so: http://www.nuvemk.com/c_categoria/seccao/1/6/9/27/ But we are getting this instead: http://www.nuvemk.com/c_categoria/seccao/9/27/ Here is the actual code: http://pastebin.com/m8ffe9db I've not yet completely understand the recursion, can I have your help in order to understand how can I recursively build the URI segments? Thanks a lot in advance, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Help with my first recursion menu
-Original Message- From: MEM [mailto:tal...@gmail.com] Sent: quarta-feira, 28 de Outubro de 2009 15:55 To: 'php-general@lists.php.net' Subject: Help with my first recursion menu Hello all, Please have a look here: http://www.nuvemk.com/c_categoria/seccao/1 When we click on Fitofármacos, I can display the correspondent children! This is great! And I'm really happy! :) When we click on Fitofármacos children - Herbicidas, I was expecting to have returned Herbicidas childs, without losing the Fitofármacos menu item. The reason I'm losing him, I suppose, it's due the fact that the URI is not properly generated by the function responsible to parse a menu. Notice that, on the link posted above: If you click on fitofármacos and then click on herbicidas, the expected URL should be: http://www.nuvemk.com/c_categoria/seccao/1/6/9/ but I'm getting this instead: http://www.nuvemk.com/c_categoria/seccao/6/9/ If we try to navigate deeply, and inside Herbicidas we click on Herbicidas A, we are expecting an URL like so: http://www.nuvemk.com/c_categoria/seccao/1/6/9/27/ But we are getting this instead: http://www.nuvemk.com/c_categoria/seccao/9/27/ Here is the actual code: http://pastebin.com/m8ffe9db I've not yet completely understand the recursion, can I have your help in order to understand how can I recursively build the URI segments? Thanks a lot in advance, Márcio I've been told that stack is the way to go, so I'm trying to understand the following code: http://pastebin.com/m5616c88f I've commented every line so that any of you could see if I'm interpreting something wrong: I have two questions about this code, that hopefully someone on the list could explain: 1) Why do we need to remove the last array item? (on line 32): array_pop($urlStack); 2) Why we print the closed tag of the li element, after the recursive call? (on line 29) echo /li\n; Thanks a lot in advance, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow
That sounds about right yeah. You could also get a little bit clever and only retrieve the rows from your db that will go to make the array elements you'll need. It doesn't make sense to retrieve a full product list each time someone visits the page, Ok. so you only need to retrieve those that the user is interested in, which is shown by what they click on. The relation between click and the display of the corresponded array child elements, without using js, is the hardest to understand: The user will click on a link / the URL will change / the new page will be loaded to the user / the information displayed on that page should be related with the element clicked on the first step. So, the next page, should know what we have clicked before, in order to display the information accordingly. One of the ways that this can be done, is by passing params over the URL. The URL param will tell us what element have we clicked, so it should be based on URL. Once we have that, we need to ask: as that value passed on the url a correspondent array element that contains children? If so, display them. (I realize my incapacity of talking technically, by referring to pages and other odd entities. I'm sorry for that). Does the above makes any sense? Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow
Think of it a bit like an online shop selling operating systems: 1) All the main OS's you sell are on the front page - Linux, MacOS Windows 2) User clicks on Linux, and is taken to the url /products/linux and they are shown all the Linux OS's on offer (Fedora, SuSe, Ubuntu, Knoppix, etc) 3) User clicks on Fedora and is taken to the URL /products/linux/fedora and they are shown all the versions of Fedora up to 11 4) etc The URL belies what section you are on, which makes it easy for the user to remember, and easy for you to extract information from to know exactly where the user is. Obviously in the above URLs I'm assuming mod_rewrite is being used. Thanks, Ash http://www.ashleysheridan.co.uk Thanks a lot! Really. I will now start coding based on all this information and see what I will get. I'm sure that the designer will kill me later, by telling me... couldn't we just... fade in this a little bit... Ahhrrggg!!! Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] dynamic menu with show hide capabilities - understanding possible workflow
Hello all, I'm on my way to build my first dynamic menu using php. However, each time I say this, people start jumping at me crying out loud: Jquery . I don't need js for this. Really. (At least, this is what I believe). So I was wondering if It's possible to accomplish it, by using css and php only. If so, I'm wondering if something like this it's a good way for doing this: 1) Generate a multidimensional array from database table containing categories and subcategories. 2) Create a css file with two classes one that shows, another that hides. 3) Grab that array and: 3.1) print it recursively (no idea how to accomplish this) 3.2) print it with some sort of class=showThis inside the generated html element. 3.3) make a conditional somewhere (I really don't know where, and this may be related with the recursion doubt), in order to display the children elements, only when we click the parent element. And here resides my main doubt: Is the point 3.3 feasible without the use of js? I just need some directions please, Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow
Thank you all. Ok. Please stay with me, cause I still have some doubts. Not only do I need to display the subitems on click but also, when the user clicks on one menu item, I need to change the URI as well. Why? Because, each time the user clicks on a menu item (whateaver that item as childs or not), I want to display a list of products related to the clicked item. So, I was trying to avoid js, because, I don’t know that much about js. However, I’d like to do it properly, so, the only way I was allowing the use of js, was by do not disabling the back button functionality and by allowing a add to favorites option as well, allowing the URI changing… O.o Anyway, let’s face it: Js is my only option, could this be a nice workflow, for an unobtrusive solution? 1) Generate the multidimensional array from query. 2) Generate the ul / li menu (echo + foreach) displaying all child elements as well. 3) Apply the anchor to the list items. 4) Apply some js to that ul / li that: 4.1) will be responsible for show/hide elements. 4.2) Will be responsible to show/hide elements only when some DOM node(?) as children. 4.3) Change the URI on click, so that some information can be showed based on uri segment. Can I have your help to fill the blanks here, or, if there are to many, just an orientation reference, in order to get started… Thanks a lot once again, Márcio From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: segunda-feira, 26 de Outubro de 2009 14:38 To: MEM Cc: php-general@lists.php.net Subject: Re: [PHP] dynamic menu with show hide capabilities - understanding possible workflow On Mon, 2009-10-26 at 13:28 +, MEM wrote: Hello all, I'm on my way to build my first dynamic menu using php. However, each time I say this, people start jumping at me crying out loud: Jquery . I don't need js for this. Really. (At least, this is what I believe). So I was wondering if It's possible to accomplish it, by using css and php only. If so, I'm wondering if something like this it's a good way for doing this: 1) Generate a multidimensional array from database table containing categories and subcategories. 2) Create a css file with two classes one that shows, another that hides. 3) Grab that array and: 3.1) print it recursively (no idea how to accomplish this) 3.2) print it with some sort of class=showThis inside the generated html element. 3.3) make a conditional somewhere (I really don't know where, and this may be related with the recursion doubt), in order to display the children elements, only when we click the parent element. And here resides my main doubt: Is the point 3.3 feasible without the use of js? I just need some directions please, Regards, Márcio Everything there is feasible without Javascript except for the clicking part, which is pretty essential to what you want. Pure CSS-only menus are still unavailable because of IE, so using some Javascript is your only option really. Is there a particular reason you are shying away from Javascript in this case? There are ways you can construct drop-down menus in a way that if Javascript is unavailable, then they fall back to becoming a bog-standard navigation bar. Also, before anyone mentions them, select lists are not the same thing as a drop-down menu, and navigating to different parts of a document upon changing the selected option is actually breaking their default behavior, and can become confusing to people who expect them to work as select lists. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] dynamic menu with show hide capabilities - understanding possible workflow
Thanks a lot for your replies. Let's see if I understand, if not, please, let me know, I'm not that proficient in English. Second try, in order to accomplish this, I have to: 1) Generate the multidimensional array from query. 2) Generate the ul / li menu (echo + foreach) displaying all child elements as well. 3) Apply the anchor to the list items. 3.1) Each anchor on this list should point to a new URL (I don't care if the page refreshes on this case). 4) Print all this on a nice way to the browser. (unobtrusive) 5) Apply js to: 5.1) HIDE the elements that need to be hidden. 5.2) SHOW what needs to be displayed. I don't want to have any onHover effect. The submenus will not appear on a onhover effect. They should appear when the user either clicks on a parent menu item, or navigates to a specific URL. Should this make me change this workflow somehow? Please have patience... :s Thanks again, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
MEM, http://www.php.net/language.oop5.reflection Regards, Tommy And brand new world opens in from of my eyes... O.O. I will search more info on this on the net... just for the records, as properties names is concern, I couldn't find any better I suppose: http://pt.php.net/manual/en/reflectionproperty.getname.php I'm just wondering, we call it like this? $property = new ReflectionProperty($myproperty); $proptertyName = $property-getName(); Can we called statically like this? $propertyName = ReflectionProperty::getName($myproperty); - this would be nice. :) The documentation is a little bit lacking, and I'm a little bit newbie, is this correct? Note: The array_keys as a possibility to retrieve ALL keys from a given array. It would be nice to retrieve ALL properties names at once as well... :) Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
@LinuxManMikeC and all @All Thanks. I was more or less aware of that possibility, however, please let me share the big picture will you guys: The main point is to access the properties name as well as values, of that object, and put them on a xls file. Instead of using mysql_num_rows, and mysql_num_files, and split and use a bunch of loops I thought: Maybe fetching as an object may help me doing this far better. However, I'm having a hard time figuring out how to make the switch. To be honest, I don't really know if iterate is the buzz word here, I would like to understand a little bit more the following: We have in our hands an Object returned by a Fetch_All w/ fetch_obj option applied to it, that object, when I do var_dump, reveals himself as in object, containing an array and, each key of that array corresponds the column names of our table or tables we have previously fetched. However, since we are working with an object, should we think differently than if we were working with an array? If so, it is, in the fact, iteration, the best option we have to put all properties and values into a xls file? Or there are far better options for that? @Lester Yes, actually, I was having only one record on the database, but I believe that is far to less. Since I was not been able to see if I was getting one object, or several objects. That make me think of that. Thanks :) And because of that, I was able (I hope) to properly understand Fernando example: @Fernando foreach ( $records as $record ) { foreach( $record as $column=$value ) { echo $column is $value\n; } } So the first foreach will iterate over each object of stdClass that corresponds to each record of mysql data fetched, then, for each of them, take the associative array key and the corresponding value... Correct? :DDD However, is this the right track to archive the goal stated above, or, they are far better ways for doing so? Regards, Márcio -Original Message- From: Lester Caine [mailto:les...@lsces.co.uk] Sent: sexta-feira, 9 de Outubro de 2009 07:23 To: php-general@lists.php.net Subject: Re: [PHP] Newbie: Array of objects iteration Fernando Castillo Aparicio wrote: I think you are just looking for the key in the wrong place. Try: foreach ( $records as $record ) { foreach( $record as $column=$value ) { echo $column is $value\n; } } You've got the columns names in each record, not in the global recorset. print_r($record); often helps - you can see what is actually returned and check that you have names rather than numbers for the fields ;) print_r($records); becomes a little large if you have a lot of results so use with care :) -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
Correct about my example, although I'm not sure if you get each record as an array or as an object. Anyway, you can iterate both. And if you want to get the column names, I suppose you could use array_keys() on the first record if you receive an array, or maybe get_object_vars() if it's an objecs (note that with this you get an array with keys and values). I've found PDOStatement-getColumnMeta(). There's a big fat warning saying this is experimental, but you could take a look in case you need more data on the columns. Hope it helps. Right now, I have something like this: foreach ($objRecord as $record) { //we will have a new line. $xls_file .=\n; foreach ($record as $column=$value) { $xls_file .= $value.\t; } } The only thing I need now, is to put on top, the column names, and I have myself a xls file. YUpii!! I just need the column names... I will take a look on those functions you have mentioned. Thanks a lot, :) Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
Right now, I have something like this: foreach ($objRecord as $record) { //we will have a new line. $xls_file .=\n; foreach ($record as $column=$value) { $xls_file .= $value.\t; } } The only thing I need now, is to put on top, the column names, and I have myself a xls file. YUpii!! I just need the column names... I will take a look on those functions you have mentioned. Thanks a lot, :) Márcio Update: PDO::FETCH_OBJ Returns an anonymous object with property names that correspond to the column names returned in your result set. I will give a shot on array_keys however, is there any method to access the PROPERTIES NAMES of a given object? Regards, M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
Dear all, it's done. Can I call your help for the remain issues please, I'm sure they are easy to explain, and at some extend, common: http://pastebin.com/m691d3e66 Instead of saving to the database, if I do a print_r or a var_dump, I get the charsets quite ok. However, they do not appear properly in the xls file. I've tried to use utf8_encode but I was not sure where to apply it, and I end up with the same strange chars on the .xls file. If I write a meta tag containing charset information on the script that generates the file, I get headers already send message. I've tried to add Content-type: application/x-msdownload; *charset=UTF-8;* but no success either... Would a proper use of utf8_encode solve this? If so, where? Thanks in advance, M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Array of objects iteration
Done. print utf8_decode($xls_file); Regards, Márcio -Original Message- From: MEM [mailto:tal...@gmail.com] Sent: sexta-feira, 9 de Outubro de 2009 18:19 To: 'MEM'; 'Fernando Castillo Aparicio'; 'Lester Caine'; 'php- gene...@lists.php.net' Subject: RE: [PHP] Newbie: Array of objects iteration Dear all, it's done. Can I call your help for the remain issues please, I'm sure they are easy to explain, and at some extend, common: http://pastebin.com/m691d3e66 Instead of saving to the database, if I do a print_r or a var_dump, I get the charsets quite ok. However, they do not appear properly in the xls file. I've tried to use utf8_encode but I was not sure where to apply it, and I end up with the same strange chars on the .xls file. If I write a meta tag containing charset information on the script that generates the file, I get headers already send message. I've tried to add Content-type: application/x-msdownload; *charset=UTF- 8;* but no success either... Would a proper use of utf8_encode solve this? If so, where? Thanks in advance, M. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie: Array of objects iteration
Hello all, I'm grabbing all records from a table using: $records = $stmt-fetchAll(PDO::FETCH_OBJ); return $records; In order to display the values we can do: foreach ($records as $record) { echo $record-id; echo $record-name; } However, I'd like to grab, also, the *column names*. I've tried: foreach ($records as $column=$value) { echo $column is $value\n; } But I get: Catchable fatal error: Object of class stdClass could not be converted to string Can I have your help on how can I properly get the column values? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] FILTER_VALIDATE_INT - newbie question
Hello all, I'm having this strange behavior, and I do not understanding why... When I use FILTER_VALIDATE_INT I'm unable to get, on my input box, values starting with 0(zero), or values that are greater (in length) then 10 digits. I was expecting to be able to input the all range of integers. I've tried this: if (!filter_var($telefone, FILTER_VALIDATE_INT)) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } And this: if (!filter_var($telefone, FILTER_VALIDATE_INT, array(options = array(min_range=-1, max_range=9 { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } And this: if (filter_var($telefone, FILTER_VALIDATE_INT, array(options = array(min_range=0, max_range=9))) == false ) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } No success. :s What am I not getting? Thanks, Márcio Ps- Anyone knows where can we grab a good source information about FILTER_VALIDATE_INT specifically? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] FILTER_VALIDATE_INT - newbie question
[sic] Before your e-mail, I've considering the use of this: if (!is_numeric($telefone)) { $erros['numberofsomething'] = 'Error - only numbers please.'; } I meant this of course: if (!is_numeric($numberofsomething)) { $erros['numberofsomething'] = 'Error - only numbers please.'; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] FILTER_VALIDATE_INT - newbie question
Well, it was only a guess, but if you look at the integer limit on 32-bit systems, you'll see that the upper limit for numbers is 2147483647 (or 2^31-1) which would explain maybe your upper limit problem. Also, I think you're getting confused over the zero with exactly what you are asking PHP to do. filter_var() returns true if the filter matches. If the 0 match is returned as a false, then filter_var() will return false. You're then inverting that with a !, all of which is inside an if() statement. Essentially this would mean that if the filter returns false then the instructions inside of the if statement are carried out. I always thought that that was a limit of the number of digits an integer value could have, and not the actually int value... I guess I was wrong. :s You are right, I've tested with: 2147483647 it worked. I've tested with: 2147483648 It displays the error. you're getting confused over the zero with exactly what you are asking PHP to do Absolutely... :( If I put 0 filter_var() will return false. If I put 0342352 filter_var() will also return false. Could we say that: if it is indeed the fact, that filter_var() returns false when it finds a 0 at the beginning of a given number... then the instructions inside of the if statement are carried out. And here may be the reason for displaying the error message when we have the 0 leading a number. And my point was exactly here If the 0 match is returned as a false Why should filter_var() do something like this? Should the filter_var() interpretate 0 as a number without boolean semantic value? Please be patient... Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] FILTER_VALIDATE_INT - newbie question
Well, at a guess, if a number is 0, PHP see's that as equivalent to a false. In this case, shouldn't php ignore the 0 as false? Also, numbers over 10 digits may be going over the limit for your PHP install, assuming PHP actually attempts to convert the string to a real integer for the purpose of the filter. This happens with two different php configurations... Is it common to have this kind of limit on php configuration? Is this something that I need to be aware of? For things this simple, THIS IS NOT SIMPLE !!! :) Newbie blood is in there! :p Kidding. ;) I've always tended to go with something like this: if(!preg_match('^[0-9 \+]$', $telefone)) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } Which will check for all common types of phone numbers, including those where the user has put spaces in to separate groups of digits, and those that contain the + for country codes. I will absolutely considerer the use of your regex. Thanks a lot. Before your e-mail, I've considering the use of this: if (!is_numeric($telefone)) { $erros['numberofsomething'] = 'Error - only numbers please.'; } In the case we need to validate other ints, that are not phones for example, only an unlimited range of ints, and we want to store that values on a database, should we have special considerations regarding the use of is_numeric ? Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] FILTER_VALIDATE_INT - newbie question
Thank you all for your replies. The issue was solved for a better fitting solution on this case, that was by using a regex expression. I've not tested the difference between using == or ===. I was using ! But, the main question that is not clear on my newbie head is, why how why couldn't this 0 be interpreted, neither as octal, or false, or whatever it may be, but as just a humble numeric value of 0. At least on the cases where FILTER_VALIDADE_INT is there. Anyway, I cannot dig in into this because I'm actually unable to offer some solutions. So, as stated, the issue was solved, by using a regex, so all good here. ;) Thanks once again, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ternary operator sintax help
Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ternary operator sintax help
Thanks. I will give up on ?= then. And use echo instead. I have declared the erros variable like this: $erros=array(); Instead of isset I’ve also tried with empty(); If I have something like this, it works: div class=mensagemErro?php echo (isset($erros['anexo'])) ? $erros['anexo'] : ''; ?/div I mean, it will show the message only when the form gets submitted. At the beginning it will have ‘’. :s Regards, Marcio From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: terça-feira, 6 de Outubro de 2009 19:49 To: MEM Cc: php-general@lists.php.net Subject: Re: [PHP] ternary operator sintax help On Tue, 2009-10-06 at 19:43 +0100, MEM wrote: Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio Firstly, ?= is a bad idea, as it's not very portable and relies on short tags being on, which causes all sorts of problems should you ever need PHP to output XML. The only reason I can see that the div will always appear is a logic error. Are you sure that the $erros['anexo'] variable is not set at some point and not just set to an empty string? An empty string is very different from an unset variable. Try using var_dump($erros['anexo']); in your code somewhere to see if the it is actually an empty string instead. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] Re: ternary operator sintax help
Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: ternary operator sintax help
Absolutely. ;) I was reporting to ashley teachings. :-) Philip, thanks for the tip. :-) Thank you all, Márcio -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: terça-feira, 6 de Outubro de 2009 21:10 To: MEM; php-general@lists.php.net Subject: Re: [PHP] Re: ternary operator sintax help just as ashley said it. On 10/6/09 3:26 PM, MEM tal...@gmail.com wrote: Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
Thanks a lot. To all. For the moment, I'm with the redirect solution that others have pointed. But after seen tedd example and watch Manuel videos, I'm starting to understand how the hidden field solution work as well. Well... I'm *starting* to understand I've not fully understand it yet, despite all your great examples. Because the structure of the code with hidden fields, seems quite different from the structure I have right now and I'm unable to make the switch. Here is the actual structure: if (isset($_POST['submit'])) { //declare variables $var = $_POST['var']; etc... //validate //process the form (send e-mail or save to database etc...) //redirect to success page. } else { Echo Sorry, couldn't process the form; } html form I suppose that the echo message telling we couldn't process the form does not appear when the form first loads, because the server side script is not requested on load, it is requested when the form submits to the php code presented on that same page (self). Tom Worster, is this precise? In the future, I will print tedd example, and Manuel scheme, and try to change the code above to accommodate hidden fields, because I still prefer having only one file. Thank you all once again, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
i agree that it does seem a bit as though Márcio is in such a hurry to make something work that the tasks of learning and understanding the fundamentals are being left aside. while that's maybe understandable, it's a bit frustrating when we're trying to explain the fundamentals. Thanks a lot. Tedd, Tom, I perfectly understand. I can only apologize. Unfortunately, I'm really REALLY on a rush. But as an additional information, I'm marking all this e-mails for latter reference and study. as i said before, a script will execute regardless. but this new script fragment does nothing except initialize $erros if $_POST['submit'] is not set (e.g. if the user requests the page without POSTing the form). i don't see a problem. this script also has the three cases i described clearly separated. now, what was your question? None. I've not properly see the structure that I was in, and according to that mistake, I've taking wrong conclusions. But thanks for pointing it out. Regards and, once again, thanks for your feedback, and I'm really sorry for not been able to properly learn with your advices. :s Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
I want to apologize to you all. I have mentioned two things on the same basket, but it was not appropriate. Since a confirmation page is not the same thing as a success page. Let's forget about the confirmation page, since it's not required. I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the form has submitted to himself. It's the only thing that we have to pay attention here, correct? Since we are not dealing with a confirmation page, or a multi-step form, the hidden field isn't necessary. It's this correct assumptions? Please advice, Regards, Márcio -Original Message- From: kranthi [mailto:kranthi...@gmail.com] Sent: sexta-feira, 2 de Outubro de 2009 11:12 To: a...@ashleysheridan.co.uk Cc: Manuel Lemos; php-general@lists.php.net; MEM; Bob McConnell Subject: Re: [PHP] Self-Process php forms or not? You say you don't use hidden fields because they can be modified too easily, yet you say you check for the submit button? Which out of the two do you do, as last time I checked, modifying one form field is as easy as changing any other! I completely agree with you. changing submit text is as easy as changing hidden fields, but its less likely for a user to modify a submit button as compared to a hidden field. moreover it just reduces my typing load. (This is just my practice) Also worth noting, you can only successfully check for the name=submit value if there is only one submit button in your form, as that is then the default (and only) submit that the form can use, so it uses that. If you have more than one submit button (and this includes image input elements) then using the keyboard will use the first submit field it finds I believe. Cant agree with you on this though. as far as i know using name= (names of the two buttons may/may not be unique) is the only way to track form submission for forms with multiple submit buttons. Please point out if you think otherwise -- Kranthi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
You can set it up any number of ways. There is no absolute need for a redirect. Everything can be done in one form, or not -- your choice. Cheers, tedd Yes. But since I don't want to display a success information + form fields, but only the success information, I believe the only way we have to do this is by either use javascript and update a div or similar, or using only php, by redirecting to another page. Is this correct? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? Ps- I've googled: php redirect success page on self submit form and similar... Regards, Márcio -Original Message- From: Bob McConnell [mailto:r...@cbord.com] Sent: sexta-feira, 24 de Abril de 2009 14:10 To: PHP-General List Subject: RE: [PHP] Self-Process php forms or not? When you have it all in one file, the first thing you do is check to see if this request was submitted from the form. If not, you send the blank form. If it was, you validate all of the data. When a validation fails, you add error messages and resend the form with any fields that passed the validation already filled in. When validation succeeds, process and move on. No muss, no fuss. Bob McConnell -Original Message- From: Sándor Tamás (HostWare Kft.) [mailto:sandorta...@hostware.hu] Sent: Friday, April 24, 2009 8:53 AM To: 'PHP-General List' Subject: Re: [PHP] Self-Process php forms or not? I think the main advantage is that if something goes wrong processing the datas, you can show the form again without redirecting again. And if you have to change the behavior of the page, you have to change only one file instead of two. SanTa - Original Message - From: MEM tal...@gmail.com To: 'PHP-General List' php-general@lists.php.net Sent: Friday, April 24, 2009 2:34 PM Subject: [PHP] Self-Process php forms or not? I'm trying to understand the advantages behind opting by using a Self-Process PHP Form, instead of having a form and then point the action of the form to another .php page. Can anyone point me some resources about this. Why using one instead of another. What are the main advantages? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
Thanks a lot to all, I will see what best fits my limited knowledge, and choose the possible option. Regards, Márcio -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: quinta-feira, 1 de Outubro de 2009 20:11 To: tedd; 'PHP-General List' Subject: Re: [PHP] Self-Process php forms or not? On 10/1/09 10:13 AM, tedd tedd.sperl...@gmail.com wrote: At 1:00 PM +0100 10/1/09, MEM wrote: One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? MEM: Here's what I do -- it's pretty simple. I use a hidden input variable I call step and monitor it as the user clicks whatever form submit they are on -- it works like so: $step = isset($_POST['step']) ? $_POST['step'] : 0; switch ($step) { case 0: // present the first form to the user // collect data // you can enhance the user experience by using javascript here. // input type=hidden name=step value=1 break; case 1: // present second form to the user // clean data // if data OK then record data in db input type=hidden name=step value=2 // if data not OK then send user back input type=hidden name=step value=0 break; case 2: //present the third form to the user // success, or confirmation, or thank you page break; } Now, to make things easier for the user, be sure to set session variables for all the data collected in the first form so that IF you send the user back to the first form, the user doesn't have to reenter everything. i do pretty much the same thing. each form in my html template files has a form name tucked away in a hidden input element. the only difference from your method is that the names are unique across the application. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie: can't access a return value.
Hi all, When I do this: $associacao_dao-listar($limit, $offset); I can var_dump the correct $limit. I can var_dump the correct $offset. I CAN'T access the object that I was hoping to get, called $records. After this, I was hoping to do var_dump($records); and see the stdClass object. Here is the listar method: public function listar($limit=null, $offset=null) { $query_str=SELECT * FROM associacao; $stmt = $this-_dbh-prepare($query_str . ' LIMIT ?, ?'); $stmt-bindParam(1, $limit, PDO::PARAM_INT); $stmt-bindParam(2, $offset, PDO::PARAM_INT); $stmt-execute(); $records = $stmt-fetchAll(PDO::FETCH_OBJ); return $records; } Any help will be greatly appreciated. Thanks a lot in advance, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: Newbie: can't access a return value.
Solved. Forget to assigning the return value of the method to anything. :S Sorry. Márcio -Original Message- From: MEM [mailto:tal...@gmail.com] Sent: sábado, 1 de Agosto de 2009 17:13 To: 'php-general@lists.php.net' Subject: Newbie: can't access a return value. Hi all, When I do this: $associacao_dao-listar($limit, $offset); I can var_dump the correct $limit. I can var_dump the correct $offset. I CAN'T access the object that I was hoping to get, called $records. After this, I was hoping to do var_dump($records); and see the stdClass object. Here is the listar method: public function listar($limit=null, $offset=null) { $query_str=SELECT * FROM associacao; $stmt = $this-_dbh-prepare($query_str . ' LIMIT ?, ?'); $stmt-bindParam(1, $limit, PDO::PARAM_INT); $stmt-bindParam(2, $offset, PDO::PARAM_INT); $stmt-execute(); $records = $stmt-fetchAll(PDO::FETCH_OBJ); return $records; } Any help will be greatly appreciated. Thanks a lot in advance, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stdClass - A newbie question
Hello everybody, In this class sketch: ?php class Pagination { ... public static function Pagination ($total_records, $limit, $page) { $total_pages = ceil($total_records / $limit); $page = max($page, 1); $page = min($page, $total_pages); $offset = ($page -1) * $limit; $pagi_obj= new stdClass; $pagi_obj-total_pages = $total_pages; $pagi_obj-offset = $offset; $pagi_obj-limit = $limit; $pagi_obj-page; return $pagi_obj; } } Why do the author used a stdClass ? What are the advantages of using a stdClass? Since we are already inside a class, why do we need to create a new object from another class, inside this one? Why do we keep the values passed as params on method Pagination inside this stdClass object, and not inside Pagination own properties for example? Any help clarifying this, knowing that I'm a newbie, Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] stdClass - A newbie question
By the way, there are many reasons for creating objects inside of other objects. This should not be considered an exception. I don't know where this code belongs to, so I can't clear out if it is good or bad OOP style. I do not intend to public judge the author, but the original article is here, just for proper credit: http://www.phpro.org/tutorials/Pagination-with-PHP-and-PDO.html Just think about everything in classes and objects - even return values or other things, that you would normally consider as volatile. (eg. a network connection) It would be a nice exercise to practice. :) Thanks for the tip. And thanks a lot for the reply, I'm almost there... one last newbie question: When we have something like this: Class Pagination { Public static function Pagination ($limit, $total_records, $page) { $pagi_obj= new stdClass; $pagi_obj-total_pages = $total_pages; $pagi_obj-offset = $offset; $pagi_obj-limit = $limit; $pagi_obj-page = $page; return $pagi_obj; ... How can we, later, have something like this, for example: $pagination_obj=Pagination::Pagination(some params) $pagination_obj-offset; ? I mean: When we instantiate the class by doing: $pagination_obj=Pagination::Pagination(some params) We will have an object ($pagi_obj) returned where the properties of that object will be *referring* to the values passed on the method argument, right? How does those $pagi_obj properties, can then be accessible by doing $pagination_obj-offset; ? I mean, they are attributes of our stdClass object (aka pagi_obj), and they are not attributes of our Pagination class, or are they? Thanks in advance, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Composition by Association - Pagination Class general question.
As for (1) even in my pre-OO days I was used to using a single generic DAO for all database access. The only time that more than one DAO existed was for a different DBMS engine. This is why I have one DAO class for MySQL, one for PostgreSQL and another for Oracle. If you are incapable of writing a single generic DAO then it just shows that you still have a lot to learn. For an idea on how this works take a look at http://www.tonymarston.net/php-mysql/databaseobjects.html Before I dig in on this DAO, I'm wondering, where should I, and how could I, properly place a JOIN on this kind of pattern? Is it easy done or, on a JOIN scenario (and I will have a lot of them) I choose probably choose another pattern? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Composition by Association - Pagination Class general question.
Thanks a lot Tony. Unfortunately for me, I'm seeing myself in no conditions for properly learning a framework. I want to learn PHP and a framework bring so many concepts at once, that I found extremely complex and time consuming do dig in, at once, right now. Since I have no more than a few months on PHP, I really need to keep it, as simple as possible, even if not perfectly structured, but, the understanding of all the steps involved should be included. Thanks a lot for your help, and sorry for, in some way, having wasting your time on this. Regards, Márcio Adding a JOIN to the SQL statement which is generated by the framework is very easy, as shown in my FAQ at http://www.tonymarston.net/php-mysql/infrastructure-faq.html#faq08. You have two choices where you can place the code: (1) In the component script. (2) In the table class, as shown in http://www.tonymarston.net/php-mysql/infrastructure-faq.html#faq84 -- Tony Marston http://www.tonymarston.net http://www.radicore.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie: Composition by Association - Pagination Class general question.
Hello, I have a Animals DAO class that I'd like to apply a pagination class to it. Between this two classes, there will be a composition relation (more precisely, an association one). My question is: Is a Pagination that has a Animal. OR Is a Animal that has a pagination? Should we create on Class Pagination a property named $_animal OR, should we create on class Animal a property named $_pagination? I'm inclined to accept the second one, since, if I put the property $_animal on my classe Pagination, I will end up, on the Pagination Class, with so many properties as pagination objects... :s Any help please? Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Composition by Association - Pagination Class general question.
Pagination is the generically applicable class - it should know nothing about what specifically it's paginating. Ok... but I need to grab values of my DAO classes, I mean, even if we paginate images on a directory or records on a database table, the pagination should have a $limit, and a offset, a way to count how many item there are to work with... So it must be related with the DAO (or other thing) on some way, so that I can grab those values and play with them on the pagination class... Should I use a Decorator Pattern to make this relation between the pagination and the DAO ? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Composition by Association - Pagination Class general question.
I don't know how your other classes are arranged, myPDO.class.php - Singleton. Makes the connection to the database possible. generalDAO.class.php - Abstract DAO Class, grabs the myPDO instance and could have other methods on the future that are shared for all the DAO classes. AnimalsDAO.class.php - DAO class with insertAnimal(); deleteAnimal(); updateAnimal(); countAnimal(); selectSpecificAnimam() methods... The same goes for the VetDAO.class.php. but personally I'd build pagination into a class that provides raw data access, then inherit that for specific types of data like animals. Efficient pagination is too tightly coupled to the data source to be separate. According to the above, does this suggestion of yours still apply? If so, what is the buzzword that I should look at so that inherit that for specific types of data like animals could be possible? What/where should I look/search to accomplish your suggestion? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie: Composition by Association - Pagination Class general question.
I would say your pagination logic belongs in myPDO.class.php. Where I have this functionality it's as simple as two arguments to the method that gets data, $page and $perpage. Setting both to false would retrieve all rows. Interesting but, still no clue, on this side, about how to accomplish that. I'm still a newbie. Can you throw some key words so that I can google them and look for a way to implement that? Thanks, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Composition by Association - Pagination Class general question.
As for (1) even in my pre-OO days I was used to using a single generic DAO for all database access. The only time that more than one DAO existed was for a different DBMS engine. This is why I have one DAO class for MySQL, one for PostgreSQL and another for Oracle. If you are incapable of writing a single generic DAO then it just shows that you still have a lot to learn. For an idea on how this works take a look at http://www.tonymarston.net/php-mysql/databaseobjects.html I'm absolutly sure that I have a lot to learn. Really a lot. :-) I have post some days ago, a way for using a generic CRUD class and DAO, but I get no replys so I wrongly suppose that my question was a nonsense question, and that CRUD and DAO would be a nonsense. As for (2) it should be obvious that pagination is not an entity in its own right that has its own properties and methods, it is merely a function which can be performed on any entity within the system. Ok... It should also be obvious that the requirements of pagination cannot be satisfied in a single class as some of the processing has to be handled in the presentation (UI) layer while the remainder is handled in the data access layer. That's why I was thinking on using a Decorator Object on the Pagination Class (that will retrieve DAO values to operate). The presentation layer needs a means to submit a request for a particular page number as well as the page size (rows per page). These two values are sent to the DAO which then translates them into values for LIMIT and OFFSET. After the DAO has issued the sql SELECT statement it needs to return two values - the current page number and the last available page number. The presentation layer then needs a mechanism to display these two values. This is explained in http://www.tonymarston.net/php-mysql/pagination.html Thanks for explain the workflow! I will read. If you still don't see how this works then you can run my sample application at http://www.tonymarston.net/php-mysql/sample-application.html You can even download the code so that you can step through it with your debugger. I haven't learn how to use a debugger yet. And I'm sure it would help me a lot on understanding some data workflow... Thanks, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Composition by Association - Pagination Class general question.
As for (1) even in my pre-OO days I was used to using a single generic DAO for all database access. The only time that more than one DAO existed was for a different DBMS engine. This is why I have one DAO class for MySQL, one for PostgreSQL and another for Oracle. If you are incapable of writing a single generic DAO then it just shows that you still have a lot to learn. For an idea on how this works take a look at http://www.tonymarston.net/php-mysql/databaseobjects.html I'm absolutly sure that I have a lot to learn. Really a lot. :-) I have post some days ago, a way for using a generic CRUD class and DAO, but I get no replys so I wrongly suppose that my question was a nonsense question, and that CRUD and DAO would be a nonsense. I'm trying to use PDO with prepare statements and BindParam, so I'm afraid that my newbility doesn't allow me to pass directly from your example to one that uses PDO. Also, I also intend to use fetchObject method instead of fetchAssoc quite often, with also puts your tutorial far away from my capacities. Because of this, I'm trying to follow what I can get on the web, using PDO and general CRUD operations: BUT: Here: 1) http://oopgarden.richardknop.com/index/view/1 or Here: 2) http://phpro.org/tutorials/Easy-Access-With-PDO-CRUD.html when we have to create complex querys by using limits, order, etc... either they are inexistent possibilities (like on the link 2), or, like on link 1 they are so close to the equivalent sql sintax that I'm questioning the advantage of having a general DAO CRUD class at all (supposing that the only advantage is that we write less words on the code). Please advice, besides the fact that we never have to code any of the SQL SELECT, INSERT, UPDATE or DELETE statements for any table as they will be generated at runtime., is there any other advantage on using a general DAO class instead of one DAO class for each table? :( Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Newbie: Composition by Association - Pagination Class general question.
Why not? Why can't you replace a call to a mysqli function with a call to a PDO function? It's not just a simple replacement - I need to add bindparam, prepare, execute, placeholders and fetchObject. But I will give it a try... Also, I also intend to use fetchObject method instead of fetchAssoc quite often, Why? What's the benefit? The fetchAssoc method gives you an array of values, while the fetchObject method gives you a container for an array of values. You still still have to work with an array of values. FetchObject maps the field names from the database as object properties with the values stored in the database. Seems quite nice. Then, to access a specific column data I just needed to: $myhandler-my_database_column_name (it seems quite nice to me) :) Why don't you learn how to use the mysqli functions before you handle the switch to PDO? What do you have to lose? I already work with PDO so, no need to switch. :-) If you read my tutorial you should see that building a SELECT statement is nothing more than combining several small strings into a larger single string. String manipulation is simple in PHP. Using this technique I can create very complex SQL statements, so don't tell me that it can't be done. I was not talking about your tutorial. I was talking about those two links, mainly the first one where, unfortunately, the difference between the code and the sql sintax is that we don't have the word SELECT and WHERE. :s However, as a positive point, this class uses BindParam and ? placeholders. But I get your point, we can cut it into smaller strings. Because you have less code to maintain. If you look carefully you should see that the only difference between the DAO for TableA and the DAO for TableB is the table name and the table structure. If you could pass these as arguments into a generic DAO then you would not need a separate DAO for each table. Yes. But you still need, for each table, to fill one or several (depending on what mysql connection method we use) arrays with values. So that less code maybe isn't that much in a way where you *significantly* reduce your maintenance burden, if you take into consideration that we take the queries for each table, but a) we add arrays and b) use a less intuitive way to add/remove/delete values to the database. As an example I have give link 1, where the difference was more or less two or three words - and the way to use the arrays where far more complicated to understand then a simple Select Sintax - hence, not that relevant. OOP is about creating reusable code to reduce the maintenance burden, so if you insist that a separate DAO for each individual table is the way to go then you don't understand how to apply the principles of OOP correctly. I will never insist just because some silly reason comes to my mind. I will however not follow a method without knowing the reasons and be convinced of them. I'm not 100% convinced of the reducing benefits for the reasons a) and b) stated above, still, maybe I get more benefits the more I add methods to the DAOs. In the next few days I will try to, based on your code, create a general DAO class that deals with PDO. And post back my frustrations back here. :D Please have patience. :D Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doubts concerning a general Insert method
Ok... according to the above posts, I've started to create my generic CRUD class however, I'm wondering: Any of you have already used a DAO design pattern in conjunction with a CRUD generic class? Know that I'm trying to create a generic CRUD class on a DAO Design pattern, it seems that it makes no sense at all. Is there an advantage on doing this? My thought: On a insert to database scenario for example: Without the CRUD generic class: to do an insert, we instantiate a DAO class and then call the insert method. Nothing more. Done. With the CRUD generic class: maybe we will have less code on the DAO site but, at the end, to insert a record, we still need to instantiate a DAO and call a insert method SO... I see not big advantage on using both... Can I have your advice on this please? Thanks, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Doubts concerning a general Insert method
Hello, I'm trying to understand a general CRUD class that I've seen here: http://www.phpro.org/classes/PDO-CRUD.html I'm learning PHP and I have some doubts on this method to generally insert data into DB. The class name is crud and here is the method: public function dbInsert($table, $values) { $this-conn(); $fieldnames = array_keys($values[0]); $size = sizeof($fieldnames); $i=1; //construction of the prepared statment $sql = INSERT INTO $table; $fields = '( ' . implode(' ,', $fieldnames) . ' )'; $bound = '(:' . implode(', :', $fieldnames) . ' )'; $sql .= $fields.' VALUES '.$bound; //prepares statement e saves it on variable $stmt $stmt = $this-db-prepare($sql); foreach($values as vals) { $stmt-execute($vals); } } To place values on the DB we do: $crud = new crud(); $values = array ( array('animal_name'='bruce', 'animal_type'='dingo'), array('animal_name'='bruce', 'animal_type'='kangaroo'), ); $crud-dbInsert('animals', $values); The doubts: 1) Names convention question: Isn't more correct to call $columname, instead of $fieldname ? 2) Why do we have this? $i=1 3) Here: $fieldnames = array_keys($values[0]); We are keeping on variable $fieldnames, the key value of the $values array, when this array is on the position 0 ? And what is *actually* the value returned, considering our array? $values = array ( array('animal_name'='bruce', 'animal_type'='dingo'), array('animal_name'='bruce', 'animal_type'='kangaroo'), ); 4) Here: foreach($values as $vals) { $stmt-execute($vals); } We are telling that, for each (line/element/index ???) of $values array, the actual value will be given(?) to vals, and the pointer goes to the next (line/element/index)... ? We then execute the prepared statement, but I don't get what are we passing as a param? I mean, what kind of think does the execute PDO method expects as a param? Why $stmt-execute($vals); and not only $stmt-execute(); ? Can I please have your help on clarifying those doubts? Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doubts concerning a general Insert method
$values[0] will give you the first element of $values, namely array('animal_name'='bruce', 'animal_type'='dingo'). array_keys will return an array containing the keys from the passed array, so in this case you'll get array('animal_name', 'animal_type'). So... since $value is an associate array of arrays, we will get, on the first key, not an array with 0, 1, like array(0,1); but array('animal_name','animal_type'), yes? When we use the implode over this array, we get: animal_name, animal_type that is the string that will pass to be prepare using the PDO prepare(). After it's finished building $sql use var_dump to look at it. You'll see that the values are specified as :animal_name and :animal_type. The : indicates to PDO that these are replaceable values. Yes. And normally, to fill those replaceable values, I was used to use bindParam(); I like this bindParam method because we can then use PDO::PARAM_INT and PDO::PARAM_STR to more accurately control the data type flow... The foreach will go through the $values array and for each row it will pass the data (e.g. array('animal_name'='bruce', 'animal_type'='dingo') for the first time round the loop) to the execute function which will effectively replace those elements in the SQL statement and execute it. Ok, so: Our $sql will be: INSERT INTO $table (animal_name, animal_type) VALUES (:animal_name, :animal_type) We then prepare this $sql by doing: prepare($sql); and the value of this preparation will be kept on a variable name $stmt. Finally, on the foreach, we will grab each value of the $values array, and keep him, on a variable called $vals, The $vals will contain this on the first occurrence of the loop: array('animal_name'='bruce', 'animal_type'='ding') and then, the var $vals will have this on the second occurrence of the loop: array('animal_name'='bruce', 'animal_type'='kanguro') etc., At the end of each of these loops, we will process the execute (that will send the statement to the database). $stmt-execute(array('animal_name'='bruce', 'animal_type'='kanguro'). So this execute will do A LOT, it will take away the 'array(' part, will see the keys of these arrays (e.g. animal_name and animal_type) compare them with the placeholder names given on the prepare statement and, replace the placeholder names with the values inside on each of this array keys. Is this correct? Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doubts concerning a general Insert method
Nice. :-) Thanks a lot Stuart for your time and explanations. Now that I have understand, I will try to move on, and understand how can we introduce bindParams on it: For a recall, here is the original class: public function dbInsert($table, $values) { $this-conn(); $fieldnames = array_keys($values[0]); $size = sizeof($fieldnames); $i=1; //construction of the prepared statment $sql = INSERT INTO $table; $fields = '( ' . implode(' ,', $fieldnames) . ' )'; $bound = '(:' . implode(', :', $fieldnames) . ' )'; $sql .= $fields.' VALUES '.$bound; //prepares statement e saves it on variable $stmt $stmt = $this-db-prepare($sql); foreach($values as vals) { $stmt-execute($vals); } } However I do have some questions that maybe someone more experimented then me could easily solve: 1) The bindParams should look similar to this: $stmt-bindParam(':animal_name', $animals-getName(), PDO::PARAM_STR ); $stmt-bindParam(':animal_type', $animals-getType(), PDO::PARAM_STR ); So, instead of looping trough an array of values, I will to do it for objects, something like: foreach($animals-listaAnimals() as $row) ... Can I have some words on this so that I can properly try to add bindParam on this class method. 2) I also need to have a way to add PDO::PARAM_STR if the values is a string or PDO::PARAM_INT if the values is int, PDO::PARAM_BOOL etc... Is there a way to control this? Using something like is_integer() and is_string(), inside if statement perhaps? If so, what about the Boolean? Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Self-Process php forms or not?
Im trying to understand the advantages behind opting by using a Self-Process PHP Form, instead of having a form and then point the action of the form to another .php page. Can anyone point me some resources about this. Why using one instead of another. What are the main advantages? Regards, Márcio
RE: [PHP] Self-Process php forms or not?
So, on your opinion, we can call that method, on some circumstances, a good practice? What about the moto: let's separate business from presentation? Thanks once again, Márcio -Original Message- From: Sándor Tamás (HostWare Kft.) [mailto:sandorta...@hostware.hu] Sent: sexta-feira, 24 de Abril de 2009 13:53 To: 'PHP-General List' Subject: Re: [PHP] Self-Process php forms or not? I think the main advantage is that if something goes wrong processing the datas, you can show the form again without redirecting again. And if you have to change the behavior of the page, you have to change only one file instead of two. SanTa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Self-Process php forms or not?
Thanks to all for your replies. I'm more elucidated about the possibilities now. I have seen here a lot of keywords to start digging. :) Thanks once again, Márcio -Original Message- From: Tony Marston [mailto:t...@marston-home.demon.co.uk] Sent: sexta-feira, 24 de Abril de 2009 14:20 To: php-general@lists.php.net Subject: Re: [PHP] Self-Process php forms or not? Having a script that is self executing - when it posts back to itself instead of a separate script - has absolutely nothing to do with the separation of business and presentation. It is possible for a single script to use separate components for the presentation, business and data access layers. -- Tony Marston http://www.tonymarston.net http://www.radicore.org MEM tal...@gmail.com wrote in message news:002b01c9c4dd$08569bc0$1903d3...@com... So, on your opinion, we can call that method, on some circumstances, a good practice? What about the moto: let's separate business from presentation? Thanks once again, Márcio -Original Message- From: Sándor Tamás (HostWare Kft.) [mailto:sandorta...@hostware.hu] Sent: sexta-feira, 24 de Abril de 2009 13:53 To: 'PHP-General List' Subject: Re: [PHP] Self-Process php forms or not? I think the main advantage is that if something goes wrong processing the datas, you can show the form again without redirecting again. And if you have to change the behavior of the page, you have to change only one file instead of two. SanTa -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] niewbie - call methods from another class
Hello, I have something like this: $stmt = $this-_dbh-prepare(INSERT INTO DOG (name_dog, race_dog, id_vet) VALUES (?, ?, ?)); $stmt-bindParam(1, $this-getNameDog() ); $stmt-bindParam(2, $this-getRaceDog()); $stmt-bindParam(3, ); $stmt-execute(); } To make this insert function work, I need to fill the id_vet database column with some values. I cannot use $this-getIdVet() because this method is not in dog class, is on the veterinary class. So my question is: How can I access the getIdVet() that is on the veterinary class to put it on the insert dog method? Thanks a lot, Márcio
RE: [PHP] PDO fetch_obj - question
Thanks. I will see. The script for my database was been generated so, I will doublecheck this uppercase issue... Regards, Márcio 2009/4/15 Thodoris t...@kinetix.gr Hi there, Ive made a fetch_obj and, as stated on some sites, it returns a anonymous object where the properties will have the name of our columns database. However, when I do this, I notice that instead of giving me the column names as they are typed on the DB I get them uppercase. So, when my database field is id_dog to retrieve the property properly I have to search for ID_DOG Why is this? Is this a normal behavior? Thanks a lot, Márcio I have just dumped an object using var_dump retrieved with pdo fetch object method: object(stdClass)#3 (4) { [id]= string(1) 1 [cat]= string(1) 1 [cod_sin]= string(6) 120014 [cod_uis]= string(2) 26 } and it seems quite normal to me. Try to see your table info using: describe `tablename`; To see what are your table's fields . Try to include more info about your system, php version etc in case you reply. It will help us to help you. -- Thodoris Done. No problem at all. The scripts as generated the database columns with uppercase. ;) Thanks for the info Thodoris. Regards, Marcio
[PHP] PDO fetch_obj - question
Hi there, Ive made a fetch_obj and, as stated on some sites, it returns a anonymous object where the properties will have the name of our columns database. However, when I do this, I notice that instead of giving me the column names as they are typed on the DB I get them uppercase. So, when my database field is id_dog to retrieve the property properly I have to search for ID_DOG Why is this? Is this a normal behavior? Thanks a lot, Márcio
[PHP] RE: PDO fetch_obj - question
Hi there, Ive made a fetch_obj and, as stated on some sites, it returns a anonymous object where the properties will have the name of our columns database. However, when I do this, I notice that instead of giving me the column names as they are typed on the DB I get them uppercase. So, when my database field is id_dog to retrieve the property properly I have to search for ID_DOG Why is this? Is this a normal behavior? Thanks a lot, Márcio Ok I found the answer here: http://bugs.php.net/bug.php?id=42632 http://bugs.php.net/bug.php?id=42632edit=1 edit=1 Regards once again, Márcio
[PHP] Newbie: handling instance values on a attribute of the same class.
Hi all, Ok. Here is a code that I'm studying: class Connection extends PDO { private $dsn = 'mysql:dbname=testes;host=127.0.0.1'; private $user = 'root'; private $password = ''; public $handle = null; function __construct( ) { try { if ( $this-handle == null ) { $dbh = parent::__construct( $this-dsn , $this-user , $this-password ); $this-handle = $dbh; return $this-handle; } } Can I replace this part: $dbh = parent::__construct( $this-dsn , $this-user , $this-password ); $this-handle = $dbh; return $this-handle; By this: (?) $this-handle = parent::__construct( $this-dsn , $this-user , $this-password ); And put a return on my getHandler method? If so, is there any special reason that we should know about using a structure like this? $dbh = parent::__construct( $this-dsn , $this-user , $this-password ); $this-handle = $dbh; return $this-handle; Thanks a lot, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newibie: fetch Obj question - data not showing.
Hello, 1) Ok, with mysqli, to fetch data from a database to a select drop down list, we would do something like this right? : ?php $result = $mysqli-query(SELECT id_cliente, nome_cliente FROM cliente); echo select id='listacliente' name='listacliente'; while($row = mysqli_fetch_assoc($result)) { echo option value=.$row['id_cliente']..$row['nome_cliente']./option; } echo /select; ? 2) What I’m trying to achieve? The same thing, but using PDO, the prepare/execute methods, and FETCH_OBJ method to fetch data. 3) Here is what I have done so far: For simplifying I’m just trying to echo: $queryh=$conn-prepare('SELECT id_cliente, nome_cliente FROM cliente'); $queryh-execute(); /*trys to access the method fetchObject of the PDOStatement generated by the execute() PDO method, and save it on $row variable:*/ $row=$queryh-fetchObject(); /*now I'm trying to echo the results. The 'id_cliente' and 'nome_cliente' are the column names of my database and, if I get it right, the fectchObject() method should allow me to access those names as anonymous properties. So: */ echo Id: .$row-id_cliente. - Nome: .$row-nome_cliente./ br; 4) Here is the issue that I’m getting: I’m getting no values from the database upon echo request. 5) Question: What is wrong with this code? :( Regards, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newibie: fetch Obj question - data not showing.
why did you forget to use the debugging functions : print_r() and var_dump() for the results? So, you'll get some idea beforehand of posting the problem here. I am looking at the code in a hurry so I cant help you much right away. Lenin http://www.twitter.com/nine_L www.twitter.com/nine_L Because I've never debug on my entire life of programming (2 months). :D In the meanwhile, I will search how to debug using print_r and var_dump. Thanks.
RE: [PHP] Newibie: fetch Obj question - data not showing.
On Behalf Of 9el On Sun, Apr 5, 2009 at 10:08 PM, MEM mailto:tal...@gmail.com tal...@gmail.com wrote: Hello, 1) Ok, with mysqli, to fetch data from a database to a select drop down list, we would do something like this right? : ?php $result = $mysqli-query(SELECT id_cliente, nome_cliente FROM cliente); echo select id='listacliente' name='listacliente'; while($row = mysqli_fetch_assoc($result)) { echo option value=.$row['id_cliente']..$row['nome_cliente']./option; } echo /select; ? 2) What Im trying to achieve? The same thing, but using PDO, the prepare/execute methods, and FETCH_OBJ method to fetch data. 3) Here is what I have done so far: For simplifying Im just trying to echo: $queryh=$conn-prepare('SELECT id_cliente, nome_cliente FROM cliente'); $queryh-execute(); /*trys to access the method fetchObject of the PDOStatement generated by the execute() PDO method, and save it on $row variable:*/ $row=$queryh-fetchObject(); /*now I'm trying to echo the results. The 'id_cliente' and 'nome_cliente' are the column names of my database and, if I get it right, the fectchObject() method should allow me to access those names as anonymous properties. So: */ echo Id: .$row-id_cliente. - Nome: .$row-nome_cliente./ br; 4) Here is the issue that Im getting: Im getting no values from the database upon echo request. 5) Question: What is wrong with this code? :( There is something definitely wrong with your code. But why did you forget to use the debugging functions : print_r() and var_dump() for the results? So, you'll get some idea beforehand of posting the problem here. I am looking at the code in a hurry so I cant help you much right away. Lenin www.twitter.com/nine_L Despite the debug Im still not getting whats going wrong. ;( Any help would be greatly appreciated. Regards, Márcio