[PHP] Scripts not running on OS X 10.3
I can't get even the test script to run on my Mac. I turned personal web sharing on, checked the httpd.config file (all is well) type 127.0.0.1/test.php in the browser and get a "source view" of the page (ie: shows up in the browser winbdow). What am I doing wrong? Thanks Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Scripts not running on OS X 10.3
I can't get even the test script to run on my Mac. I turned personal web sharing on, checked the httpd.config file (all is well) type 127.0.0.1/test.php in the browser and get a "source view" of the page (ie: shows up in the browser winbdow). What am I doing wrong? Thanks Ken > Got a line like this in your httpd.conf? > AddType application/x-httpd-php .php Yeah. both of these are uncommented in httpd.conf: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Scripts not running on OS X 10.3
Ken Tozier wrote: I can't get even the test script to run on my Mac. I turned personal web sharing on, checked the httpd.config file (all is well) type 127.0.0.1/test.php in the browser and get a "source view" of the page (ie: shows up in the browser winbdow). What am I doing wrong? Thanks Ken > Got a line like this in your httpd.conf? > AddType application/x-httpd-php .php Yeah. both of these are uncommented in httpd.conf: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps Restarted Apache? Yep. same result. Possibly have another httpd.conf file that Apache is reading? Possibly. I used the package installer from Marc liyannage's web site which seems to have done something odd to the httpd.conf file but I don't know enough unix yet to fix it without possibly screwing up. there are the following config files in the /private/etc/httpd directory: httpd.conf httpd.conf.applesaved httpd.conf.bak httpd.conf.default httpd.conf.entropy-backup.1059884513 httpd.conf.entropy-temp In addition to these, there is another config file named "httpd.conf.php" in the "/usr/local/php/" directory Which one Apache is using is a mystery to me. Anything in the error logs when you start Apache? No. this appears to be in order. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Scripts not running on OS X 10.3
Odd. To be sure it's using the conf file you want, have you tried starting Apache with the command.? /path/to/httpd -f /path/to/httpd.conf I tried your suggestion but the system won't let me modify it even with su permissions. I'm too tired and frustrated to continue tonight. Clearly, the installer must have messed something important up so I'm just going to reinstall Panther tomorrow (have to partition my drive anyway so what the heck) Thanks for all your help. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Looping through results of pg_meta_data()
I'm trying to build an html table using the results from pg_meta_data() but none of the access functions seem to work. I am getting results but just can't seem to do anything with them. Here's what I'm using to verify that results are being returned: $connstring = "dbname=pub_status user=postgres host=localhost port=5432"; $db = pg_connect($connstring); $meta = pg_meta_data($db, 'table_definitions'); echo ''; var_dump($meta); echo ''; Which yeilds: array(2) { ["field_id"]=> array(5) { ["num"]=> int(1) ["type"]=> string(4) "int8" ["len"]=> int(8) ["not null"]=> bool(true) ["has default"]=> bool(true) } ["field_name"]=> array(5) { ["num"]=> int(2) ["type"]=> string(4) "text" ["len"]=> int(-1) ["not null"]=> bool(true) ["has default"]=> bool(false) } } But none of these seem to do anything: $row_count = pg_num_rows($meta); echo $row_count; -> result a blank web page $row = pg_fetch_row($meta, 0); echo $row; -> result a blank web page $row = pg_fetch_array($meta, 0); echo $row; -> result a blank web page $row = pg_fetch_object($meta, 0); echo $row; -> result a blank web page What am I doing wrong? Thanks for any help, Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Form containing 2 menus not returning anything
I created an html form comprised of two menus but when the action method for the form calls my "handler.php" script, neither of the menu variables contain anything. Could someone point out what I'm doing wrong? Thanks, Ken Here's the relevant html: Publication: none Ashland TAB Canton Journal View: none Pub Status Pub Notes And here's the PHP handler script: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Form containing 2 menus not returning anything
Thanks John, that did the trick. I'm curious though, the PHP book I'm reading (PHP and PostgeSQL, Advanced web programming) specifically states that it's not necessary to grab form variables in this way, claiming PHP extracts all form variables behind the scenes for you. Was my original syntax something that used to be supported but has since been deprecated? Ken On Oct 23, 2004, at 10:13 AM, John Holmes wrote: if(isset($_POST['view'])) { echo $_POST['publication'] . '' . $_POST['view']; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] can't open a file
Hi I'm trying to create/open a file for write in a subfolder of the folder that contains my PHP script but am having no luck. Here's the relevant code $oldPath= '/test/old_page_'.$oldRecord['page_number'].'.txt'; $oldHand= fopen($oldPath, "w+"); if ($oldHand === true) fwrite($oldHand, $oldData); else die('Failed to open file "'.$oldPath.'" for writing!'); fclose($oldHand); The permissions for the "test" folder is set to me in a WebServer subfolder on Mac OS X. Do I need to set permissons to something else to get this to work? If so, what permissions should I use? Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] No is_date() function?
Hi I wrote a serialization function to turn arbitrary PHP variables into Macintosh plist compatible XML but see that there is no "is_date" tester as there is for bool, object, array etc. Is there a relatively simple (and robust) way to detect if a variable is a date? For example: $person = array('name'=>'bob', 'sex'=>'male', 'date_of_birth'=> $someDateHere); Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No is_date() function?
Thanks Lars I saw that one already but unfortunately, it doesn't help as it requires 3 inputs . What I'm shooting for is an 'is_date' function that returns true or false with no prior knowledge of what a variable might contain. Ken On Jul 25, 2007, at 10:08 AM, Lars Haßler wrote: Hi, there is a function to check a valid date: http://de3.php.net/ manual/de/function.checkdate.php may help Hi I wrote a serialization function to turn arbitrary PHP variables into Macintosh plist compatible XML but see that there is no "is_date" tester as there is for bool, object, array etc. Is there a relatively simple (and robust) way to detect if a variable is a date? For example: $person = array('name'=>'bob', 'sex'=>'male', 'date_of_birth'=> $someDateHere); Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No is_date() function?
On Jul 25, 2007, at 10:37 AM, Edward Kay wrote: PS: Please don't top post on mailing lists. I'm unfamiliar with the term "top post". What does it mean? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Bizarre array create error
Hi I'm trying to assign two fields of an object returned from a MySQL query and have stumbled upon the most bizarre PHP bug where I can't create two arrays in succession. Here's the MySQL query with two dummy fields to be filled in later select *, 0 as dummy_1, 0 as dummy_2 from table Here's how I'm grabbing the query results $result = array(); while ($row = mysql_fetch_object($query_result)) { $result[] = $row; } Once that's done, I try to set two of the rows to arrays like this $result-> dummy_1= array(1, 2, 3, 4); $result-> dummy_2= array('a', 'b', 'c', 'd'); If I comment out either of the above lines, the script works but with both uncommented, it seems to drop dead. It doesn't even return an error. I rebooted my system thinking PHP might have gotten into a funky state but that didn't work. I retyped the function from scratch but it still breaks on these two lines. I did a "show invisibles" and "show spaces" in BBEdit to see if there was a hidden character, none found. I did a hex dump to see if there was a hidden character that BBEdit was missing, nope. And I haven't upgraded PHP in a year so it's not a question of an unstable update. I've been doing assignments like the above for 3 years and never had a problem and in fact the exact same function works perfectly in another script.This one has me utterly stumped. Anyone have an idea what might be causing this? Or something else I could try to glean more info about the failure? Thanks in advance Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bizarre array create error
On Jul 29, 2007, at 6:49 PM, Ken Tozier wrote: Hi I'm trying to assign two fields of an object returned from a MySQL query and have stumbled upon the most bizarre PHP bug where I can't create two arrays in succession. Here's the MySQL query with two dummy fields to be filled in later select *, 0 as dummy_1, 0 as dummy_2 from table Here's how I'm grabbing the query results $result = array(); while ($row = mysql_fetch_object($query_result)) { $result[] = $row; } Once that's done, I try to set two of the rows to arrays like this $result-> dummy_1= array(1, 2, 3, 4); $result-> dummy_2= array('a', 'b', 'c', 'd'); Oops. Left out a step. This is actually how I'm doing the assignments $result[0]-> dummy_1 = array(1, 2, 3, 4); $result[0]-> dummy_2 = array('a', 'b', 'c', 'd'); If I comment out either of the above lines, the script works but with both uncommented, it seems to drop dead. It doesn't even return an error. I rebooted my system thinking PHP might have gotten into a funky state but that didn't work. I retyped the function from scratch but it still breaks on these two lines. I did a "show invisibles" and "show spaces" in BBEdit to see if there was a hidden character, none found. I did a hex dump to see if there was a hidden character that BBEdit was missing, nope. And I haven't upgraded PHP in a year so it's not a question of an unstable update. I've been doing assignments like the above for 3 years and never had a problem and in fact the exact same function works perfectly in another script.This one has me utterly stumped. Anyone have an idea what might be causing this? Or something else I could try to glean more info about the failure? Thanks in advance Ken -- 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] Bizarre array create error
On Jul 30, 2007, at 12:05 AM, Tom Ray [Lists] wrote: Ken Tozier wrote: Hi I'm trying to assign two fields of an object returned from a MySQL query and have stumbled upon the most bizarre PHP bug where I can't create two arrays in succession. Here's the MySQL query with two dummy fields to be filled in later select *, 0 as dummy_1, 0 as dummy_2 from table Here's how I'm grabbing the query results $result= array(); while ($row = mysql_fetch_object($query_result)) { $result[]= $row; } Once that's done, I try to set two of the rows to arrays like this $result-> dummy_1= array(1, 2, 3, 4); $result-> dummy_2= array('a', 'b', 'c', 'd'); If I comment out either of the above lines, the script works but with both uncommented, it seems to drop dead. It doesn't even return an error. Is this all of your code? No. Here's the full function: function get_document_type_for_pub($inPubID) { $query = "select doc_type.*, 0 as rect, 0 as usable_rect, 0 as usable_width, 0 as usable_height, 0 as column_width, 0 as column_offsets, 0 as box_widths from publication, doc_type where publication.id=".$inPubID." and publication.doc_type=doc_type.id"; $queryResult= $this->db->query_database($query); $result = $queryResult[0]; // convert numbers $result->id += 0; $result->page_width += 0.0; $result->page_height += 0.0; $result->top_margin += 0.0; $result->left_margin += 0.0; $result->bottom_margin += 0.0; $result->right_margin+= 0.0; $result->column_count+= 0; $result->gutter_width+= 0.0; $result->folio_height+= 0.0; $result->usable_width+= 0.0; $result->usable_height += 0.0; $result->column_width+= 0.0; // calculate derived values $result->usable_width = $result->page_width - $result->left_margin - $result->right_margin; $result->usable_height = $result->page_height - $result->top_margin - $result->bottom_margin; $result->column_width = ($result->usable_width - $result- >gutter_width * ($result->column_count - 1)) / $result->column_count; /*--*/ /* Next two lines are where the problem starts */ /* If I comment either of them out the script runs */ /* but with both uncommented, it dies /*--*/ // create the rect and usable rect records $result->rect = array(0, 0, $result->page_width, $result- >page_height); $result->usable_rect = array($result->left_margin, $result- >top_margin, $result->usable_width, $result->usable_height); // create the offset and box width arrays $offsets= array(); $widths = array(); $left = $result->left_margin; $width = $result->column_width; $inc= $result->column_width + $result->gutter_width; for ($i = 0; $i < $result->column_count; $i++) { $offsets[] = $left; $widths[] = array('column_width'=> $i + 1, 'point_width'=> $width); $left += $inc; $width += $inc; } $result->column_offsets = $offsets; $result->box_widths = $widths; return $result; } Do you have some sort of output display for your results? No. Once it hits the "create the rect and usable rect records" assignments, it's like the script didn't even get called. Nothing returns. Does PHP generally return errors to the browser? I'm not using a browser, I'm making direct calls to the script from a Cocoa class on a Mac Does that script run on the same machine? Yes. I'm doing all development on my MacBook and the scripts all live in my local web folder. If it's on another machine is that machine running the same version? I ran this on a server with Apache 2.2.4, PHP 5.2.3 and mySQL 5.0.18. Have you referenced that other script to make sure that it *is* exactly the same? I cut and pasted it from its original home to a new script and it stopped working. Thanks for replying Tom. I'll check out the php.ini settings tomorrow Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bizarre array create error
On Jul 30, 2007, at 2:23 AM, Paul Novitski wrote: At 7/29/2007 09:59 PM, Ken Tozier wrote: /*--*/ /* Next two lines are where the problem starts */ /* If I comment either of them out the script runs */ /* but with both uncommented, it dies /*--*/ // create the rect and usable rect records $result->rect = array(0, 0, $result- >page_width, $result- >page_height); Does this typo exist in your script? "$result- >page_height" with a space between - and >? No. Must be an email thing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Bizarre array create error
On Jul 31, 2007, at 2:00 AM, Richard Lynch wrote: On Sun, July 29, 2007 5:49 pm, Ken Tozier wrote: I'm trying to assign two fields of an object returned from a MySQL query and have stumbled upon the most bizarre PHP bug where I can't create two arrays in succession. Here's the MySQL query with two dummy fields to be filled in later select *, 0 as dummy_1, 0 as dummy_2 from table Here's how I'm grabbing the query results $result = array(); while ($row = mysql_fetch_object($query_result)) { $result[] = $row; } Once that's done, I try to set two of the rows to arrays like this $result-> dummy_1= array(1, 2, 3, 4); $result-> dummy_2= array('a', 'b', 'c', 'd'); $result is an array and you are treating it like an object... While this is supposed to work, I think, it's pretty confusing to this naive reader... $result['dummy_1'] = array(1, 2, 3, 4); would make more sense... That doesn't work. (I tried already) You have to use the "->" syntax for objects returned by an MySQL query. And you do realize that your actual objects are ELEMENTS of the array $result, not $result itself... So maybe you want something more like: $row1 = $result[0]; $row1->dummy_1 = array(1, 2, 3, 4); Yeah. My original post was incorrect. I'm actually doing something more like your above suggestion $result[0]->dummy_1 = array(1, 2, 3, 4); I posted the complete function at 1:04 a.m. July 30 if you want to take a look That said, you're altering an Object that MySQL returned, and I've got NO IDEA what kind of an object that is, or what you're allowed to cram into its variables... The weird thing is, I've been doing this type of assignment for a couple of years, haven't upgraded my copy PHP for a year, but all of a sudden it breaks. Very puzzling... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Unexpected values in PHP array
Hi I think this is probably just a misunderstanding on my part, but I'm creating associative arrays with string keys from MySQL query results and when I put a value in the array, I get the expected key association along with an index key that has a different value. For example: If I have a table "Foo," do a select, perform coersions on the results, and place the coerced value in an array with a key, a second uncoerced value is also placed in the array with an index key. I know all associative arrays have both key and index accessors, but I would think that the values should be the same. Here's the full function. (Note: The line where values are added to the array is: "$fields [$key] = $value;" after the "coersions" switch statement) function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query) as $row) { $fields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) { switch ($coersions[$key]) { case'integer': $value += 0; break; case'float': $value += 0.0; break; case'datetime': $value = new date_object($value); break; case'base64_decode': $value = base64_decode($value); break; case'hex_decode': $value = $this->hex_decode($value); } } $fields[$key] = $value; } // perform grouping if requested if ($group_by_key == null) $rows[$recordKey] = $fields; else { $groupKey = $fields[$group_by_key]; if ($rows[$groupKey] == null) $rows[$groupKey]= array();
[PHP] Unexpected values in an associative array
Hi I think this is probably just a misunderstanding on my part, but I'm creating associative arrays with string keys from MySQL query results and when I put a value in the array, I get the expected key association along with an index key that has a different value. For example: If I have a table "Foo," do a select, perform coersions on the results, and place the coerced value in an array with a key, a second uncoerced value is also placed in the array with an index key. I know all associative arrays have both key and index accessors, but I would think that the values should be the same. Here's the full function. (Note: The line where values are added to the array is: "$fields [$key] = $value;" after the "coersions" switch statement) function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query) as $row) { $fields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) { switch ($coersions[$key]) { case'integer': $value += 0; break; case'float': $value += 0.0; break; case'datetime': $value = new date_object($value); break; case'base64_decode': $value = base64_decode($value); break; case'hex_decode': $value = $this->hex_decode($value); } } $fields[$key] = $value; } // perform grouping if requested if ($group_by_key == null) $rows[$recordKey] = $fields; else { $groupKey = $fields[$group_by_key]; if ($rows[$groupKey] == null) $rows[$groupKey]= array();
Re: [PHP] Unexpected values in an associative array[Solved]
Turns out that objects returned from SQL queries contain two parts for every field, one with a string key and one with an index key. Adding an "is_numeric" test on the keys allows you to filter out the numeric keys if you want to. For example: foreach ($row as $key => $value) { if (!is_numeric($key)) { /* do stuff here */ } } Ken On Jul 31, 2007, at 10:35 AM, Ken Tozier wrote: Hi I think this is probably just a misunderstanding on my part, but I'm creating associative arrays with string keys from MySQL query results and when I put a value in the array, I get the expected key association along with an index key that has a different value. For example: If I have a table "Foo," do a select, perform coersions on the results, and place the coerced value in an array with a key, a second uncoerced value is also placed in the array with an index key. I know all associative arrays have both key and index accessors, but I would think that the values should be the same. Here's the full function. (Note: The line where values are added to the array is: "$fields [$key] = $value;" after the "coersions" switch statement) function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query) as $row) { $fields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) { switch ($coersions[$key]) { case'integer': $value += 0; break; case'float': $value += 0.0; break; case'datetime': $value = new date_object($value); break; case'base64_decode': $value = base64_decode($value); break; case'hex_decode': $value = $this->hex_decode($value); } } $fields[$key] = $value; }
Re: [PHP] Unexpected values in an associative array[Solved]
On Jul 31, 2007, at 11:40 AM, Robin Vickery wrote: Or don't get numeric keys in the first place: foreach ($this->db->query($query, PDO::FETCH_ASSOC) as $row) Robin: Bingo! That did the trick. I knew my solution was hokey but I haven't used PDO before this project so wasn't aware of what it did behind the scenes. Thanks everyone for the quick replies. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unexpected values in an associative array
On Jul 31, 2007, at 12:06 PM, Instruct ICC wrote: array(6) { ["task_id"]=> int(22) [0]=> string(2) "22" ["container_id"]=> int(3784) [1]=> string(4) "3784" ["name"]=> string(12) "108-6972.XTG" [2]=> string(24) "3130382D363937322E585447" } What is $coersions or $inQuery['coersions']? Maybe a var_dump or a print_r on that for the list? For the above record, $coersions is an associative array of the form array('task_id'=> 'integer', 'container_id'=> 'integer', 'name'=>'hex_decode'); I found that I was doing a lot of coersions with results of SQL queries to turn them into real integers, floats or decode from base64/ hex before I could use them so rolling all that ugly stuff into the query makes it so users of the function don't have to do coersions any more. There may be a better way to perform coersions from string types returned by PDO queries and their real types but I'm a PDO noob so don't know if one. What is $value and what is this supposed to do: case'integer': $value += 0; break; case'float': $value += 0.0; If $value is a string, you should quote your 0 and 0.0. What add 0 or 0.0 to an int or float respectively? The point of these is to convert the strings to ints, floats, decode them etc... What's the extra "[]" about in $rows[$groupKey][] = $fields; Maybe that's where your duplicates are coming from although I don't see duplicates in your output. Another thing I found the need for was to group rows in a select result by specific keys. For example say a query gets all ads in a publication, and you want to physically group them by page. That's what that group function does. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Does PDO prevent class functions from calling other class functions?
Hi I've been writing PHP classes for around two years now but all of a sudden, the things I used to do don't work any more. I have a class that implements utility functions for database calls using PDO and am finding that I can't call one utility function from within another. If each function is called by itself from a script, they work perfectly. This is really basic stuff so I'm very puzzled why it isn't working. The only difference between these new classes and my old classes is the use of PDO. Could PDO be causing all these headaches? Anyone see where I'm screwing up? Thanks in advance Ken Here's the '__construct' function of the included 'MySQLDatabase' class function __construct($inDomain, $inUser, $inPassword, $inDBName) { try { $this->db = new PDO('mysql:host='.$inDomain.';dbname='.$inDBName, $inUser, $inPassword); // set error reporting $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . ""; die(); } } Here's the utility class so far // MySQLDatabase is a DB access class that handles a bunch of stuff like pulling values out of a query // value coersion etc. I've tested this for the last day or so and it seems to be stable. include_once('MySQLDatabase.php'); class PMXUtilities { private $db; function __construct() { $domain = 'localhost'; $user = 'root'; $password = ''; $db_name= 'pagemanager'; $this->db= new MySQLDatabase($domain, $user, $password, $db_name); } // if this is called on its own, it works function site_for_pub($inPubID) { $query= 'select site.id, site.site_name from site, publication where publication.id='.$inPubID.' and publication.site=site.id'; $coersions = array('id'=> 'integer'); $args = array('query'=> $query, 'coersions'=> $coersions); $queryResult= $this->db->query_database($args); if (count($queryResult) > 0) return $queryResult[0]['id']; else return 'Error: PMXUtilities.site_for_pub_id failed while fetching site info for publication:'.$inPubID; } / if this is called on its own, it works function directory_type_id_for_name($inName) { $query = 'select id from directory_type where name="'.$inName.'"'; $coersions = array('id'=> 'integer'); $args = array('query'=> $query, 'coersions'=> $coersions); $queryResult= $this->db->query_database($args); if (count($queryResult) > 0) return $queryResult[0]['id']; else return 'Error: PMXUtilities.site_for_pub_id failed while fetching directory type id for directory:'.$inName; } // this function never gets past the first "echo" function directory_path_for_pub_id($inPubID, $inDirType) { echo 'entered: directory_path_for_pub_id'; // seems to die on next line as the 'echo site' line never prints $site = $this->site_for_pub_id($inPubID); echo 'site: '.$site.''; /* $dirTypeID = $this->directory_type_id_for_name($inDirType); echo 'dir_type: '.$dirTypeID.''; $query = "select server.server_name, directory.path from directory, server, site where directory.type=".$dirTypeID." and directory.server=server.id and server.site=site.id and site.id=".$site; echo $query.''; $queryResult= $this->db->query_database($query); return $queryResult[0]->server_name.$queryResult[0]->path; */ } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.
Re: [PHP] Does PDO prevent class functions from calling other class functions?
On Aug 2, 2007, at 12:03 PM, Nathan Nobbe wrote: can you supply an error or warning that php is giving ? it would help to determine the problem. How would I go about that? I just took a quick look at the try/catch documentation and it looks like it's my responsibility to throw exceptions which isn't particularly useful if it's PHP itself that is doing something unexpected http://www.php.net/manual/en/language.exceptions.php -nathan On 8/2/07, Ken Tozier <[EMAIL PROTECTED]> wrote: Hi I've been writing PHP classes for around two years now but all of a sudden, the things I used to do don't work any more. I have a class that implements utility functions for database calls using PDO and am finding that I can't call one utility function from within another. If each function is called by itself from a script, they work perfectly. This is really basic stuff so I'm very puzzled why it isn't working. The only difference between these new classes and my old classes is the use of PDO. Could PDO be causing all these headaches? Anyone see where I'm screwing up? Thanks in advance Ken Here's the '__construct' function of the included 'MySQLDatabase' class function __construct($inDomain, $inUser, $inPassword, $inDBName) { try { $this->db = new PDO('mysql:host='. $inDomain.';dbname='.$inDBName, $inUser, $inPassword); // set error reporting $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . ""; die(); } } Here's the utility class so far // MySQLDatabase is a DB access class that handles a bunch of stuff like pulling values out of a query // value coersion etc. I've tested this for the last day or so and it seems to be stable. include_once('MySQLDatabase.php'); class PMXUtilities { private $db; function __construct() { $domain = 'localhost'; $user = 'root'; $password = ''; $db_name= 'pagemanager'; $this->db = new MySQLDatabase ($domain, $user, $password, $db_name); } // if this is called on its own, it works function site_for_pub($inPubID) { $query = 'select site.id, site.site_name from site, publication where publication.id='.$inPubID.' and publication.site=site.id'; $coersions = array ('id'=> 'integer'); $args = array ('query'=> $query, 'coersions'=> $coersions); $queryResult= $this->db- >query_database($args); if (count($queryResult) > 0) return $queryResult[0]['id']; else return 'Error: PMXUtilities.site_for_pub_id failed while fetching site info for publication:'.$inPubID; } / if this is called on its own, it works function directory_type_id_for_name($inName) { $query = 'select id from directory_type where name="'.$inName.'"'; $coersions = array ('id'=> 'integer'); $args = array ('query'=> $query, 'coersions'=> $coersions); $queryResult= $this->db- >query_database($args); if (count($queryResult) > 0) return $queryResult[0]['id']; else return 'Error: PMXUtilities.site_for_pub_id failed while fetching directory type id for directory:'.$inName; } // this function never gets past the first "echo" function directory_path_for_pub_id($inPubID, $inDirType) { echo 'entered: directory_path_for_pub_id'; // seems to die on next line as the 'echo site' line never prints $site
Re: [PHP] Does PDO prevent class functions from calling other class functions?
On Aug 2, 2007, at 12:19 PM, Nathan Nobbe wrote: > On 8/2/07, Ken Tozier <[EMAIL PROTECTED]> wrote: > How would I go about that? I just took a quick look at the try/catch > documentation and it looks like it's my responsibility to throw >exceptions which isn't particularly useful if it's PHP itself that is > doing something unexpected well, youre not throwing an exception here in your code, your doing something called swallowing the exception. which is typically not a good practice. catch (PDOException $e) { print "Error!: " . $e->getMessage() . ""; die(); } and you could show us the output from $e->getMessage() thats where the script is blowing up. calling die() after that will obviously stop processing so you have no hope of recovering gracefully. There is no error. The browser calls the script and paints a blank screen. If I do a "view source" same deal, nothing. Here's the MySQLDatabase "query_database' function that passes the actual call to PDO function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query, PDO::FETCH_NAMED) as $row) { $rowFields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) $value = $this->coerce_value($value, $coersions[$key]); $rowFields[$key] = $value; } // perform grouping if requested if ($group_by_key == null) $rows[$recordKey] = $rowFields; else { $groupKey = $rowFields[$group_by_key]; if ($rows[$groupKey] == null) $rows[$groupKey]= array(); $rows[$groupKey][] = $rowFields; } $rowCounter++; } return $rows; } else { // return last insert ID return ($this->db->lastInsertId() + 0); } } catch (PDOException $error) { print "Error!: " . $error->getMessage() . ""; //die(); } } And here's a modified version of the "directory_path_for_pub_id" with a try/catch function directory_path_for_pub_id($inPubID, $inDirType) { echo 'entered: directory_path_for_pub_id'; try { $site = $this->site_for_pub_id($inPubID); echo 'site: '.$site.''; } // Tried both of these. Result: blank window/blank "view source' catch ($e) catch (Exception $e) {
Re: [PHP] Does PDO prevent class functions from calling other class functions?
On Aug 2, 2007, at 12:15 PM, Andrew Ballard wrote: Ken, Your method name is site_for_pub, and you are trying to call site_for_pub_id. I am indeed. What a bonehead. Thanks Andrew that fixed it. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PDO::ATTR_TIMEOUT script specific?
Hi I have a script that needs to get ad information from two different sources, a primary and fallback. The primary source is a high traffic (and poorly designed/unpartitioned MSSQL database) with millions of records that gets locked up when 'certain folks' (ie executives) perform large queries. What I'd like to be able to do is set a timeout for a query to this database of 5 to 10 seconds and branch to the fallback database if the timeout expires. I can't just use the fallback as my primary as it doesn't always have the most up to date info. It's really only for placeholder queries until the primary frees up. So the question is, does setting PDO::ATTR_TIMEOUT affect all scripts or just the one that set the variable? Thanks in advance Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function -> action
On Aug 3, 2007, at 9:39 AM, Ken Tozier wrote: On Aug 3, 2007, at 2:38 AM, Ralph Kutschera wrote: Hallo! I'm working on a project, where we distinguish between "functions" and "actions" in design, although in PHP both are implemented as functions. Is there a chance that PHP can use the word "action" as "function"? E.g.: public function doSomething() { } public action doSomethingElse() { ... } ... is actually the same but would help to see the design also in the code. You could define a generic action function function action($funcName, $funcArgs) { return $funcName($funcArgs); } Actually, this might be better as it makes no assumptions about the function's argument list. function action() { $func = func_get_arg(0); $expr = func_get_args(); $expr = array_slice($expr, 1); $expr = implode(', ', $expr); $expr = $func.'('.$expr.');'; return eval($expr); } You lose the ability to pass by reference but that might not be important for your script. and use it on any function you want to use as an action function function printColor($color) { echo 'color: '.$color.''; } function printArea($width, $height) { echo 'area: '.($width * $height).''; } action('printColor', 'blue'); action('printArea', 3, 5); You could then pass in any function that is visible to the action function. You lose some efficiency but get your action function Then again, you could also just prepend action functions with 'action_' TIA, Ralph -- 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] function -> action
On Aug 3, 2007, at 2:38 AM, Ralph Kutschera wrote: Hallo! I'm working on a project, where we distinguish between "functions" and "actions" in design, although in PHP both are implemented as functions. Is there a chance that PHP can use the word "action" as "function"? E.g.: public function doSomething() { } public action doSomethingElse() { ... } ... is actually the same but would help to see the design also in the code. You could define a generic action function function action($funcName, $funcArgs) { return $funcName($funcArgs); } and use it on any function you want to use as an action function function printColor($color) { echo 'color: '.$color.''; } function printArea($width, $height) { echo 'area: '.($width * $height).''; } action('printColor', 'blue'); action('printArea', 3, 5); You could then pass in any function that is visible to the action function. You lose some efficiency but get your action function Then again, you could also just prepend action functions with 'action_' TIA, Ralph -- 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] PDO lastInsertID always returns zero for MySQL tables
Hi In the past, I always used mysql_insert_id() and never had a problem, but now that I'm using PDO, I'm finding that it always returns zero. The tables are identical between the two methods but where mysql_insert_id works $pdo_connection->lastInsertID() doesn't. The PDO documentation states that you need to feed lastInsertID something called a "sequence object." I'd never heard of those before so after some reading here http://www.mckoi.com/database/ SQLSyntax.html#7 it looks like you have to create these yourself . But MySQL tables already seem to have a built-in sequence (as evidenced by the auto_increment flag when creating tables) and creating another one for a given table could lead to id collisions. So basically, the question is: Is it possible to get valid "lastInsertIds: using PDO with a MySQL database that mirrors the behavior of mysql_insert_id? Thanks for any help Ken Here' the function. The lastInsertID call comes in the 'else' branch of the "if (strpos ($query, 'insert') === false)" test function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query, PDO::FETCH_NAMED) as $row) { $rowFields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) $value = $this->coerce_value($value, $coersions[$key]); $rowFields[$key] = $value; } // perform grouping if requested if ($group_by_key == null) $rows[$recordKey] = $rowFields; else { $groupKey = $rowFields[$group_by_key]; if ($rows[$groupKey] == null) $rows[$groupKey]= array(); $rows[$groupKey][] = $rowFields; } $rowCounter++; } return $rows; } else { // next line prints OK on inserts echo 'query type was: insert'; // but this always returns zero return ($this->db->lastInsertId()); } } catch (PDOException $error) { print "Error!: " . $error->getMessage() . ""; die(); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO lastInsertID always returns zero for MySQL tables [SOLVED]
Disregard. After more head scratching I found that I was branching to the 'insert' handler without calling this->db->query($query). On Aug 5, 2007, at 9:18 PM, Ken Tozier wrote: Hi In the past, I always used mysql_insert_id() and never had a problem, but now that I'm using PDO, I'm finding that it always returns zero. The tables are identical between the two methods but where mysql_insert_id works $pdo_connection->lastInsertID() doesn't. The PDO documentation states that you need to feed lastInsertID something called a "sequence object." I'd never heard of those before so after some reading here http://www.mckoi.com/database/ SQLSyntax.html#7 it looks like you have to create these yourself . But MySQL tables already seem to have a built-in sequence (as evidenced by the auto_increment flag when creating tables) and creating another one for a given table could lead to id collisions. So basically, the question is: Is it possible to get valid "lastInsertIds: using PDO with a MySQL database that mirrors the behavior of mysql_insert_id? Thanks for any help Ken Here' the function. The lastInsertID call comes in the 'else' branch of the "if (strpos ($query, 'insert') === false)" test function query_database($inQuery) { $query = $inQuery; $coersions = null; $object_key = null; $group_by_key = null; if (is_array($inQuery)) { $query = $inQuery['query']; $coersions = $inQuery['coersions']; $object_key = $inQuery['object_key']; $group_by_key = $inQuery['group_by_key']; } try { // determine query type if (strpos($query, 'insert') === false) { $rows = array(); $rowCounter = 0; foreach ($this->db->query($query, PDO::FETCH_NAMED) as $row) { $rowFields = array(); $recordKey = $rowCounter; foreach ($row as $key => $value) { // remember this key if it matches the user specified object key if (($object_key != null) && ($key == $object_key)) $recordKey = $value; // perform user specified coersions if ($coersions != null) $value = $this->coerce_value($value, $coersions[$key]); $rowFields[$key] = $value; } // perform grouping if requested if ($group_by_key == null) $rows[$recordKey] = $rowFields; else { $groupKey = $rowFields[$group_by_key]; if ($rows[$groupKey] == null) $rows[$groupKey]= array(); $rows[$groupKey][] = $rowFields; } $rowCounter++; } return $rows; } else { // next line prints OK on inserts echo 'query type was: insert'; // but this always returns zero return ($this->db->lastInsertId()); } } catch (PDOException $error) { print "Error!: " . $error->getMessage() . ""; die(); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Unexpected values in an associative array
On Aug 8, 2007, at 12:43 AM, Robert Cummings wrote: On Tue, 2007-08-07 at 23:28 -0500, Richard Lynch wrote: On Tue, July 31, 2007 11:06 am, Instruct ICC wrote: What is $value and what is this supposed to do: case'integer': $value += 0; This is a silly hack in place of: $value = (int) $value; And it's flawed since a string containing a float having 0 added to it will still be float :) Good points. Thanks. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php command to open a url?
I've been looking around in the php documentation for a couple of hours now but can't seem to find any functions to open a url in the current browser window. Does php allow this? If so, could someone point me to a link? Basically what I'm trying to do is loop back in a login form until a user enters a valid username/password and then redirect to that user's personal info page. Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] imagestring() not working
Hi all, I'm trying to create a little function that generates tabs dynamically and am having no luck with the imagestring() function. I checked out the documentation and even cut and pasted the example but it always chokes the browser when the page containing an imagestring() line is loaded. Anyone see what I'm doing wrong? Thanks Ken - Here's the script so far: echo ""; var_dump($image); var_dump($inactive); var_dump($poly); var_dump($over); var_dump($active); var_dump($text_color); echo ""; // if I comment out the next line, the browser displays the above var_dumps // but when it's uncommented, the browser displays a blank screen imagestring ($image, 1, 0, 0, "bobo", $text_color); // header("Content-type: image/png"); // imagepng($im); ?> And here's the return from gd_settings() array(11) { ["GD Version"]=> string(27) "bundled (2.0.15 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(false) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] No luck creating dynamic images
I've been trying for most of the day to generate a simple dynamic image in my php script without any success. It seems obvious that something isn't right with my php environment as even the simplest images (like a rectangle) only yield the broken link icon. Does anyone know of any in depth resource for php trouble shooting? I've already scoured the php.net site and it wasn't of much help. Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No luck creating dynamic images
Enable FULL error reporting. I tried this with error_reporting(E_ALL); and ran the script in multiple browsers no errors reported. Also ran phpinfo(); (as suggested by Jay Blanchard) which worked without problem. The settings under GD were all enabled for the common image types. Anybody see any glaring errors in the following? Here's the html: And here's the php: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No luck creating dynamic images
Thanks everyone for the help. I got it working now. Turns out at least part of the problem was invisible characters from the cut & past example code I found on the php site. Ken On Nov 1, 2004, at 3:48 PM, Robert Sossomon wrote: Works fine for me, though the image needs to be lengthened some to get the whole text in it. Check your server settings... Robert Ken Tozier is quoted as saying on 11/1/2004 2:51 PM: Enable FULL error reporting. I tried this with error_reporting(E_ALL); and ran the script in multiple browsers no errors reported. Also ran phpinfo(); (as suggested by Jay Blanchard) which worked without problem. The settings under GD were all enabled for the common image types. Anybody see any glaring errors in the following? Here's the html: And here's the php: header("Content-type: image/png"); $im = imagecreate(100, 50) or die("Cannot Initialize new GD image stream"); $back_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); imagepng($im); imagedestroy($im); ?> -- Robert Sossomon, Business and Technology Application Technician 4-H Youth Development Department 200 Ricks Hall, Campus Box 7606 N.C. State University Raleigh NC 27695-7606 Phone: 919/515-8474 Fax: 919/515-7812 [EMAIL PROTECTED] -- 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] Using system resident fonts with "image_xxx" routines?
Is it possible to use fonts on a system with php's image routines? The GD supplied fonts look pretty crappy and if possible, I'd like to just use fonts available on the system (I'm on a Mac) rather than downloading a bunch of customized fonts exclusively for use with php's image_xxx routines. Thanks Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Using fonts in TrueType suitcases on a Mac?
I'm trying to use some of the truetype fonts on my mac with PHP's "imagettfbbox()" routine but since all my fonts are contained within suitcases, I don't know how to get them to work. I found one non-suitcase TrueType font that loads fine so I know the basic mechanism works and the script has the correct permissions to access fonts. Anyone know how to use TrueType Suitcases with PHP? Thanks for any help Ken
Re: [PHP] Re: Using fonts in TrueType suitcases on a Mac?
On Nov 7, 2004, at 12:32 AM, David Schlotfeldt wrote: I don't know if this will help you but you could try converting them. Its hard to explain how to do .. but here is a start.. 1) Burn the fonts to a Mac cd (burn the Cd for a mac.. not a PC.. if you do you will loose information) 2) Bring the cd to a windows machine and use MacDisk to read the cd. you can get macdisk from: macdisk.com 3) Grab the fonts off the Cd (using MacDisk) 4) Then use CrossFont (http://www.asy.com/) to convert them. This maybe more work then its worth... but its one possible solution. I don't own a PC and I'm developing for a dual G4 running OS 10.3. Would this type of conversion work when put back on a Mac? Thanks, David Ken Tozier wrote: I'm trying to use some of the truetype fonts on my mac with PHP's "imagettfbbox()" routine but since all my fonts are contained within suitcases, I don't know how to get them to work. I found one non-suitcase TrueType font that loads fine so I know the basic mechanism works and the script has the correct permissions to access fonts. Anyone know how to use TrueType Suitcases with PHP? Thanks for any help Ken -- 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] short type codes for use in array conversion
I found a method for converting javascript arrays to PHP arrays here: "http://aspn.activestate.com/ASPN/Cookbook/PHP/Recipe/414334"; and would like to expand the list of types the function knows about. It looks like 's' = string, 'a' = array but 'i' for integer and 'n' for number don't work. Is there a list of type codes somewhere on the php site? I did a search but apparently didn't hit upon the correct phrase as all searches came up with zero results. Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] short type codes for use in array conversion
Thanks for the link Jasper. That solved it. Ken On Aug 26, 2005, at 1:22 AM, Jasper Bryant-Greene wrote: Ken Tozier wrote: I found a method for converting javascript arrays to PHP arrays here: "http://aspn.activestate.com/ASPN/Cookbook/PHP/Recipe/ 414334" and would like to expand the list of types the function knows about. It looks like 's' = string, 'a' = array but 'i' for integer and 'n' for number don't work. Is there a list of type codes somewhere on the php site? I did a search but apparently didn't hit upon the correct phrase as all searches came up with zero results. The JS code is creating a string in the same way that serialize() does, so that it can be passed through unserialize() to get the actual array. There isn't really a description (that I could find, anyway) in the PHP manual of how serialize() actually stores its values. Take a look at "PHP's Serialization Format", about 1/3 of the way down on this page: http://hurring.com/code/perl/serialize/ Jasper -- 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] Way for script to discover it's path?
I'm working on an auto-include mechanism for some complex scripts and rather than have all the paths to the various components hard coded, I'd like to have the script walk up the hierarchy looking for it's specified includes. Is it possible to do this? I looked at the various file related php functions but didn't see anything resembling 'my_path()' Thanks Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Way for script to discover it's path?
Thanks Jordan, that did the trick! Ken On Sep 18, 2005, at 6:40 PM, Jordan Miller wrote: Hey Ken, The variable you want is already a superglobal known as $_SERVER ['SCRIPT_FILENAME']. See: http://www.php.net/reserved.variables Do something like this to get started: echo $_SERVER['SCRIPT_FILENAME']; Good luck. Jordan On Sep 18, 2005, at 4:58 PM, Ken Tozier wrote: I'm working on an auto-include mechanism for some complex scripts and rather than have all the paths to the various components hard coded, I'd like to have the script walk up the hierarchy looking for it's specified includes. Is it possible to do this? I looked at the various file related php functions but didn't see anything resembling 'my_path()' Thanks Ken -- 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
[PHP] Using DOM object, how?
I was looking at the PHP DOM documentation here "http://www.php.net/ manual/en/ref.dom.php" (which is rather sparse in the way of examples) and can't even get to square one. Here's an example from the php site: '); echo $doc->saveXML(); $doc = new DOMDocument(); $doc->loadXML(''); echo $doc->saveXML(); ?> Problem is, it chokes on the first line with the error: Fatal error: Undefined class name 'domdocument' in /folder/ dom_test.php on line 1 Anyone know how to use this thing? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using DOM object, how?
The first line of that page - " The DOM extension is the replacement for the DOM XML extension from PHP 4." makes me suspect that it may be a PHP 5 feature, and sure enough, a look in the changelog confirms this. php.net/ChangeLog-5.php#5.0.0b1 So if you are using php < 5.0, that would explain your error. That was it. (php 4.3.1 something) Just downloaded 5.0.5 and it works fine now. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using DOM object, how?
Next question: I don't see any obvious DOM method for including scripts or css links like "
Re: [PHP] Re: Using DOM object, how?
I would be extremely careful with this.. because sadly PHP's XML generator uses the short form whenever possible. will *NOT* work in most browsers such as FireFox. Will work. Thanks for the heads up. Looks like if you define the tag like $script= $dom->createElement('script',''); <-- empty string It tacks on an end tag. I personally would love to see a function where I could set it to use the long form. and when importing if it's in long form.. set that long from flag on automatically .. this would have saved me _hours_ of debugging work. are you trying to just generate the entire html page using only the XML DOM? .. or are you doing this in conjunction with another language such as XSL? So far, just playing. But ultimately I'd like to generate the whole page using dom calls. It seems much cleaner for what I'm doing than creating a whole bunch of large functions that do nothing more than echo prestyled html. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using DOM object, how?
Rats. Looks like you can't encapsulate DOM objects in your own classes. I tried this and the browser 'view source' shows a completely empty document. createScriptElement('howdy.js'); class MyDom { function MyDom() { $dom = new DOMDocument('1.0', 'iso-8859-1'); return $this; } function createScriptElement($inScriptPath) { $script= $this->dom->createElement('script',''); $script->setAttribute('language', 'javascript'); $script->setAttribute('src', 'howdy.js'); $this->dom->appendChild($script); echo $this->dom->saveXML(); } } ?> If the element adding code is in the same function as the dom create, it works createElement('script',''); $script->setAttribute('language', 'javascript'); $script->setAttribute('src', 'howdy.js'); $dom->appendChild($script); echo $dom->saveXML(); return $this; } } ?> Also if the DOM object is declared outside the class, and class functions access it as a global it works createScriptElement('howdy.js'); class MyDom { function MyDom() { return $this; } function createScriptElement($inScriptPath) { global $dom; $script= $dom->createElement('script',''); $script->setAttribute('language', 'javascript'); $script->setAttribute('src', $inScriptPath); $dom->appendChild($script); echo $dom->saveXML(); } } ?> Would be nice if you could encapsulate it though... You can probably add an empty text node to the script tag, or a text node consisting of a single space, or something like that, to make it use the long form. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- 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: Using DOM object, how?
On Sep 19, 2005, at 3:26 PM, Vance Rodriguez wrote: I am used to seeing global class variables initialized in the class level if they are available to the class's $this statement. createScriptElement('howdy.js'); class MyDom { protected $dom; function __construct() { $this->dom = new DOMDocument('1.0', 'iso-8859-1'); } function createScriptElement($inScriptPath) { $script= $this->dom->createElement('script',''); $script->setAttribute('language', 'javascript'); $script->setAttribute('src', 'howdy.js '); $this->dom->appendChild($script); echo $this->dom->saveXML(); } } ?> On Sep 19, 2005, at 3:35 PM, comex wrote: $dom = new DOMDocument('1.0', 'iso-8859-1'); Shouldn't this be $this->dom = new DOMDocument('1.0', 'iso-8859-1'); ? That didn't work either. tried a few other things as well and it looks like PHP forces you to define DOM documents in one hideous monolithic code block without any of the encapsulation benefits classes provide. Not sure if this intentional due to security issues or if it's a bug. Anyone think of a reason why it would be necessary to prohibit DOM object embedding in a class? Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using DOM object, how?
Thanks Jasper Works perfectly on my Mac now as well. Ken On Sep 19, 2005, at 4:58 PM, Jasper Bryant-Greene wrote: createScriptElement('howdy.js'); print($x->saveXML()); class MyDom { private $dom; /* __construct() = PHP5 constructor */ function __construct() { $this->dom = new DOMDocument('1.0', 'iso-8859-1'); /* No need to return $this from a constructor */ } function createScriptElement($scriptPath) { $script = $this->dom->createElement('script', ''); $script->setAttribute('type', 'text/javascript'); $script->setAttribute('src', $scriptPath); $this->dom->appendChild($script); /* Doesn't make sense for a createScriptElement() method to also print out the XML, so I made a separate method and called that from the mainline code. */ } function saveXML() { return $this->dom->saveXML(); } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using DOM object, how?
Even better, you can just extend the DOMDocument class, which is perfect, since I'm basically just adding convenience methods. Thanks all for your help Ken createScriptElement('howdy.js'); $x->createCSSLinkElement('howdy.css'); $x->createStyledDivElement('bugColumnTitle', "I'm a styled piece of text!"); print($x->saveXML()); class MyDom extends DOMDocument { function createScriptElement($inPath) { $new_elem = $this->createElementAndAppend('script', null); $new_elem->setAttribute('type', 'text/javascript'); $new_elem->setAttribute('src', $inPath); } function createCSSLinkElement($inPath) { $new_elem = $this->createElementAndAppend('link', null); $new_elem->setAttribute('href', $inPath); $new_elem->setAttribute('rel', 'stylesheet'); $new_elem->setAttribute('media', 'screen'); } function createStyledDivElement($inStyle, $inData) { $new_elem = $this->createElementAndAppend('div', $inData); $new_elem->setAttribute('class', $inStyle); } function createElementAndAppend($inType, $inData) { // setting null inData to an empty string forces a close tag which is what we want $elem_data= ($inData == null) ? '' : $inData ; $new_elem= $this->createElement($inType, $elem_data); $this->appendChild($new_elem); return $new_elem; } } ?> On Sep 19, 2005, at 6:13 PM, Ken Tozier wrote: Thanks Jasper Works perfectly on my Mac now as well. Ken On Sep 19, 2005, at 4:58 PM, Jasper Bryant-Greene wrote: createScriptElement('howdy.js'); print($x->saveXML()); class MyDom { private $dom; /* __construct() = PHP5 constructor */ function __construct() { $this->dom = new DOMDocument('1.0', 'iso-8859-1'); /* No need to return $this from a constructor */ } function createScriptElement($scriptPath) { $script = $this->dom->createElement('script', ''); $script->setAttribute('type', 'text/javascript'); $script->setAttribute('src', $scriptPath); $this->dom->appendChild($script); /* Doesn't make sense for a createScriptElement() method to also print out the XML, so I made a separate method and called that from the mainline code. */ } function saveXML() { return $this->dom->saveXML(); } } ?> -- 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: Using DOM object, how?
On Sep 19, 2005, at 7:19 PM, Stephen Leaf wrote: On Monday 19 September 2005 06:04 pm, Ken Tozier wrote: Not a bad Idea. You might like this function I made then ;) function createElement($parentNode, $name, $elements=array()) { $node = $this->Dom->createElement($name); for ($x=0; $x < count($elements); $x++) { if ($elements[$x][0] == ".") { $node->nodeValue = $elements[$x][1]; } else { $node->setAttribute($elements[$x][0], $elements[$x] [1]); } } $parentNode->appendChild($node); } general all purpose element creator for those of us that hate to call setAttribute a hundred times ;) That's pretty slick. I'll have to steal it : ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Intelligent "session_destroy()"
I'm writing a bunch of scripts that will all use a common session and am a bit confused about when to manually destroy sessions and/or when php automatically destroys them for me. For example: If a user starts a session, leaves their computer on and goes home for the weekend, when they come back on Monday will their session still exist on the server? Could they pick right up where they left off? Thanks Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Strange array access problem
I'm having a major problem with what seems, on it's face, to be a really basic array function. What happens is on the browser end, I've written some javascript code that packages up javascript variables in native PHP format and sends the packed variables to a PHP script on the server via a POST and XMLHTTP. On the server end, the PHP script grabs the packed variables out of the $_POST, strips slashes and uses the "unserialize" command. Here's the function that gets the post data $unpacked_data= GetDataFromPOST(); And here's a var_dump of $unpacked_data as it appears in the browser array(1) { ["handler"]=> array(1) { ["0"]=> string(9) "databases" } } I'm able to get the "handler with no problem like so: $parts= $unpacked_data['handler']; Which yields the following var_dump array(1) { ["0"]=> string(9) "databases" } Here's where the problem starts. I've had no luck whatsoever trying to get items of $parts. I've tried all of the following and each of them return NULL $part_1 = $parts[0]; $part_1 = $parts['0']; $part_1 = $parts["0"]; $part_1 = $parts[48]; <- ASCII character for zero In desperation, I also tried this foreach($parts as $key => $value) { var_dump($key); // => string(1) "0" var_dump($value); // => string(9) "databases" $parts_1 = $parts[$key]; // => NULL; } But no luck I also checked the type and size of the key like so foreach($parts as $key => $value) { echo gettype($key); // => string echo sizeof($key); // => 1 } Anyone have any insights as to what the heck is going on here? This should be a piece of cake but It's stopped me cold for a full day and a half Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Strange array access problem
Rob , Very helpful, Thanks! I'll try to rewrite the serializer on the javascript end to encode integer keys as integers. Ken On Oct 26, 2005, at 1:23 AM, Robert Cummings wrote: On Wed, 2005-10-26 at 01:06, Robert Cummings wrote: I did some more investigating. Your problem appears to be PHP5 specific. I manually created the serialize string I assumed you had, but PHP4 was smarter than me and auto converted the string key to an integer once again; however, PHP5 for some reason during unserialization maintained the string type for the key, however it was not able to access the value because upon attempting to access the value I'm assuming it did a type conversion to integer... additionally I got the following error notice when trying to access the value: Notice: Undefined index: 0 in /home/suds/foo.php on line 25 NULL The following can duplicated the error: $ser = 'a:1:{s:1:"0";s:3:"foo";}'; $unser = unserialize( $ser ); var_dump( $unser ); var_dump( $unser['0'] ); FYI this is not considered a bug in PHP since PHP will not produce serialized output in that form (IMHO it is a bug since it deviates from an expected functionality with respect to how serialized data should be encoded-- but then maybe there's a doc somewhere that states you have to convert integer strings to real integers for keys *shrug*): http://bugs.php.net/bug.php?id=27712 Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- 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] Strange array access problem
Got it working. Thanks for all your help Rob. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Accessing photos outside the web folder
I'm writing a content management application which saves file paths in a database and allows users to search the database for those files. Problem I'm having is that although the PHP script that handles the database queries works fine, when the search results get to the browser, all the paths are off limits. I can't just move the photos inside the web folder as we're talking tens of thousands of images that are already organized into a folder structure that must be maintained as is. Is there a way to allow the web page to see these photos? The images are stored on a Windows box and all the web server stuff is on a G5 Macintosh running OS 10.4 3 (in case that has any bearing on the matter). Thanks for any help Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php