
snorky
Members-
Posts
55 -
Joined
-
Last visited
Never
Everything posted by snorky
-
Suddenly getting errors when accessing mysql db using PHP
snorky replied to snorky's topic in MySQL Help
Oddly enough, I tried that (or something similar, apparently omitting/goofing up a step). Following your instructions fixed it. Thank you. -
MySQL 4.1 CentOS 4.5 NOTE: I have more than a full-time job administering a network with 2500+ nodes and 6000+ end users. Since these old versions of MySQL and CentOS have been working, I haven't updated them. "If it ain't broke, don't fix it." That said, the server that hosts the mysql server got hit by an unexpected power-down -- someone was testing the backup power generator ... I have several databases on that instance of mysql. All seemed to have survived - except, of course - the most important one. On the 'other' DBs, users can run the php/html programs and access data without problems. Note: everything on this MySQL server has run smoothly for several years prior to the big hit. On the 'big' database - the one that is now suffering - [*]the users cannot access the server; for these users the PHP performs only SELECT functions [*]the maintainers - the people whose PHP performs SELECT, INSERT, DELETE, UPDATE functions cannot access the server [*]the DBA - me - cannot use PHP, the MySQL console, and Webmin to access data note: I don't use PHPAdmin on this - phpmyadmin broke after an update and I never bothered to fix it The failed commands and the error messages errors: users: $link=mysql_connect('xxx.xxx.xxx.15','guest',''); PHP CODE: if (!$link) { die('Unable connect to the server at this time. Version 20110216.1155: '. mysql_error()); } ERROR MSG: Unable connect to the server at this time. Version 20110216.1155: Access denied for user 'guest'@'xxx.xxx.xxx.22' (using password: NO) MAINTAINERS: CODE: $link=mysql_connect('xxx.xxx.xxx.15','maintainer','password'); { die('Unable connect to the server at this time. Version 20091006.1300: ' . mysql_error()); } ERROR MSG: Unable connect to the server at this time. Version 20091006.1300: Access denied for user 'maintainer'@'xxx.xxx.xxx.22' (using password: YES) DBA: COMMANDS/ERROR MSGS: I get a panoply of errors, depeding on what I'm doing. Whether I log on to mysql as root or as dba, all of the errors refer to user '' mysql -u root -p --- I no longer need a password for root or dba when SELECTing from the mysql table, the passwords for root dba display in plain text, instead of encrypted mysql> SET PASSWORD FOR 'dba'@'localhost' = PASSWORD('newpass'); ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' Note that the user is '' mysql> UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='dba' AND Host='localhost'; ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user' I get the error command denied to user '' with any db admin statements such as SELECT, INSERT, UPDATE, SET, DELETE. As a result, I cannot create a new user or superuser, elevate the privileges for an existing user, delete existing users. For example, using Webmin, Failed to delete users : SQL delete from user where user = 'dba' and host = '' failed : DELETE command denied to user ''@'localhost' for table 'user' I have yesterday's mysqldump of this (and each) non-system database, i.e., all but the mysql DB. However, I don't see where restoring the non-problem DBs' data will solve the problem of users, passwords, and privileges. It appears to me that the mysql DB is corrupted. Is there a way to fix that? Or am I (as usual) going off half-cocked?
-
(whacks self upside the head) Regex ! Of course! I spent hours going down the wrong path, running down a ditch. Thank you.
-
mysql select ... where ... in or like Consider these statements: Code: select * from[i] sometable[/i] where[i] thiscolumn[/i] in(1,2,3); That returns all rows where column thiscolumn is one of those three values. Code: select * from [i]sometabl[/i]e where [i]thiscolumn[/i] like("a%"); That returns all rows where the first character of a column thiscolumn is 'a'; What I'm trying to do is to combine the two concepts as in something like select * from [i]sometable[/i] where [i]thiscolumn[/i] in('like("b%")','like("c%")'); I'm trying to return all rows where the first character of a column thiscolumn is 'b' or 'c'; That syntax is wrong. I've tried assigning variables set @var1: 'like="b%"'; set @var2: 'like="c%"'; then using those vars in the in predicate. select * from [i]sometable[/i] where [i]thiscolumn[/i] in('b','c'); Again, bad syntax. I could use ... Code: thiscolumn like("b%") or thiscolumn like("c%") or thiscolumn like("da%") or .... ... ad nausem. But if there are many values in the set, it becomes quite clunky. I've tried the mysql manual and google. The problem with those is trying to figure out how to ask the question. A forum like this gives me the ability to (hopefully)seek, explain, and find the solution. In this case I don't have the luxury of using php; I have to do it within mysql. Ideas? __________________ Certified Digital Forensics Examiner, MCSE, etc., etc. Nature: Nerd. Nurture:Linux
-
That makes sense. Thanks. However.... the script still does not return what I expect. If I throw in some debugging code, I can see that "everything" would work correctly if the values of $a and $c (in the complete script at the bottom) are passed from getValues() to lookUps(). [ pseudo code ] : getValues() $a = [statementX] $inputFile; return $a; lookUps() global $a; $aa = "nslookup" . $a; exec($aa); // This is not the problem. // The problem is that there is nothing to execute (see below). loop0() global $a; while(!feof($inputFile)) // repeats lookUps() until feof($inputFile) { $values = getValues(); lookUps($values); } lookUps() should process $a to create $aa - an argument for an execute statement: exec(), shell_exec(), passthru(), etc. However, no value for $a is passed to this function. I can tell there is no value by testing for $a before the $aa assignment. Using or not using the global and return statements makes no difference. $a is not passed from getValues() to lookUps(). The early parts of the script (see below) work well. In other words, the values for $a and $c are created correctly. I don't like to ask so many questions, but after several hours of research and testing I'm still hitting the wall. I really appreciate the help of people far more skilled than I. The complete script is: <?php // -- run nslookup for hostname & ip address and compare results -- */ // -----begin vars ----------- $dir = "."; // folder for input and results files $thisDay = date("Ymd"); // date used in file names ex: 20100316 $fileIn = $thisDay . "-panda.txt"; // input file $fileOut = $thisDay . "-results.txt"; // results file $handleIn = fopen($fileIn,'r'); // open input file read-only $textA = " - computers without Panda\n"; // part of header line in results page $textB = $thisDay . $textA; // -----end vars ------------ // ----- begin functions ------------- function finis() // the last step in the script { global $fileIn; global $fileOut; close($fileIn); close($fileOut); exit (); } function openFileOut() // create log file { global $fileOut; global $textB; fopen($fileOut,'w'); // open the output file for write fwrite($fileOut,$textB); // print header line at top of results page // leave results page open for more writes } function openFileIn() // open input file (text) { global $fileIn; fopen($fileIn,'r'); // open the input file for read } /* --- example of values in function getValues() $data = OHE-CL30,10.11.1.59 $z = 19 // count of chars in entire line $b = 8 // location of comma $a = 0,7 "OHE-CL30" // 1st substring in $data $c = 9,18 "10.11.1.59" // 2nd substring in $data --- end example -------------- */ function getValues() { global $handleIn; global $thisDay; global $fileIn; global $fileOut; global $textA; global $textB; $data = fgets($handleIn); // the string being read // example: OHE-CL30,10.11.1.59 // each line of input file resembles this : hostname,ip address */ $z = strlen($data); // how many chars in entire line // example: 19 $b = strpos($data,","); // find the comma // example: 8 $a = substr($data,0,($b - 1)); // hostname // example: 0,7 "OHE-CL30" $c = substr($data,($b + 1),($z - 1)); // ip address // example: 9,18 "10.11.1.59" return $a; return $c; } function lookUps() // compare and reverse compare IPs & HOSTNAMES { global $a; global $c; $aa = "nslookup" . $a; $cc = "nslookup" . $c; // then use shell_exec() or exec() or passthru() } function loop0() { global $handleIn; global $a; global $c; $counter = 1; // initialize counter @1 while(!feof($handleIn)) { $values = getValues(); lookUps($values); } } // ----- end functions ------------- /* ------------ runtime ------------ */ openFileIn(); openFileOut(); loop0(); echo " ======== closing files and going home =========\n"; finis(); ?>
-
"Functions can both accept and return values. Its a simple concept." The problem: how do I pass the values of the variables in function getValues() to function lookUps() ? Using the global declaration doesn't work.
-
I have a script that consists of Some variables declared in the body of the script. They will become global variables used throughout the script. 5 functions: function openFileIn() - opens a text file for reading function openFileOut() - creates and opens a log file (text) for writing function loop0() - is a loop that uses global variables AND calls the next two functions(see below) function getValues() - reads one line from the input file and processes it to create variables specific to the current iteration of the loop function lookUps() - executes commands using the global variables AND (hopefully) variables created in function getValues(), writes the results to the log file, and hands control back to the while statement. All of the variables declared in the body of the script easily pass to functions by identifying them as global when using them in a function. The problem: how do I pass the values of the variables in function getValues() to function lookUps() ? Using the global declaration doesn't work. Note: the "echo" commands in functions loop0(), getValues(), and lookUps() are there for debugging. The results of the echo commands tell me where things are working correctly - or not. The script: <?php /* -- compare nslookup for hostname & ip address -- */ // -----begin vars ----------- $dir = "."; // folder for input and results files $thisDay = date("Ymd"); // date used in file names ex: 20100316 $fileIn = $thisDay . "-panda.txt"; // input file $fileOut = $thisDay . "-results.txt"; // results file $handleIn = fopen($fileIn, 'r'); // open input file read-only $textA = " - computers without Panda\n"; // part of header line in results page $textB = $thisDay.$textA; // -----end vars ------------ // ----- begin functions ------------- function finis() // the last step in the script { global $fileIn; global $fileOut; close ($fileIn); close ($fileOut); exit(); } function openFileOut() // create log file { global $fileOut; global $textB; fopen($fileOut, 'w'); // open the output file for write fwrite($fileOut, $textB); // print header line at top of results page } // leave results page open for more writes function openFileIn() // open input file (text) { global $fileIn; fopen($fileIn,'r'); // open the input file for read } /* --- example of values in function getValues() $data = OHE-CL30,10.11.1.59 $z = 19 // count of chars in entire line $b = 8 // location of comma $a = 0,7 "OHE-CL30" // 1st substring in $data $c = 9,18 "10.11.1.59" // 2nd substring in $data --- end example -------------- */ function getValues() { global $handleIn; $data=fgets($handleIn); // the string being read // example: OHE-CL30,10.11.1.59 // each line of input file resembles this: // hostname,ip address $z = strlen($data); // how many chars in entire line // example: 19 $b = strpos($data,","); // find the comma // example: 8 $a = substr($data,0,($b-1)); // hostname // example: 0,7 "OHE-CL30" $c = substr($data,($b+1),($z - 1)); // ip address // example: 9,18 "10.11.1.59" // used for debugging; it shows that this function works as expected // $m = ", "; // echo $data . $z . $m . $b . $m . $a . $m . $c . "\n"; } function lookUps() // compare and reverse compare IPs & HOSTNAMES { global $a; global $c; global $fileOut; // echo "a = " . $a . ", c = " . $c . ", logfile = " . $fileOut . "\n"; // for debugging $aa = "nslookup" . $a . " >> " . $fileOut; $cc = "nslookup" . $c . " >> " . $fileOut; shell_exec($aa); shell_exec($cc); // exec($aa); // exec($aa); // passthru($aa); // passthru($cc); } function loop0() { global $handleIn; $counter=1; while (!feof($handleIn)) { getValues(); // echo $counter . "\n"; // testing for progress of the loop $counter++; lookUps(); } } // ----- end functions ------------- /* ------------ runtime ------------ */ openFileIn(); openFileOut(); loop0(); echo " ======== closing files and going home =========\n"; finis(); ?>
-
var_dump($DOCUMENT_ROOT,$PHP_SELF,$DOCUMENT_ROOT.$PHP_SELF); throws NULL NULL string(0) ""
-
When I run either of the code snippets below, the browser returns Page Last Updated: 12.31.1969 /* format of date display */ $fmt_ymd = "m.d.Y"; /* date page was last modified */ $file_last_modified = date(filemtime($_SERVER['SCRIPT_FILENAME'])); /* display foooter */ $last_modified = date($fmt_ymd,$file_last_modified); echo(" Page Last Updated: " . $last_modified); or /* format of date display */ $fmt_ymd = "m.d.Y"; /* date page was last modified */ $file_last_modified = filemtime("$DOCUMENT_ROOT$PHP_SELF"); /* display foooter */ $last_modified = date($fmt_ymd,$file_last_modified); echo(" Page Last Updated: " . $last_modified); Trust me - the page was not last modified 40 years ago. All pages involved were modified today. I get the same results on different servers, one with php 5.2.6, the other with 4.4.4
-
I wrote (like 10,000,000 others) a script to recursively read and list the contents of directories. However, when I print the results to the screen I want to include the contents of the <title></title> block and/or the first nn words in the <body></body> (somewhat like the results from a search engine). How do I read specific, limited content from an HTML file?
-
How do I rotate images (or banners...) every n seconds? I use the following code to rotate the images every time the page is loaded. However, I want to rotate the images every n seconds while the page is displayed. <?php /* --------------------------------------------------------------------------------- find all files (in this case images) in a folder and rotate randomly when page is loaded or refreshed note: as written here, all files must be valid images and there can be no sub-folders --------------------------------------------------------------------------------- */ $filenum=0; // initialize counter $pix=array(); // create array $usedir="../images/const/"; // show location of images to rotate if ($handle = opendir($usedir)) // open folder for reading { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file=$file++; // increment the counter $pix[]=$file; // select the next element from the array } } closedir($handle); } shuffle($pix); // shuffle the elements of the array $displ1=$pix[1]; // create var to id image to display $displ2=$pix[2]; // damphyno why I did this print // display the randomly-selected image "<img src='" . $usedir.$displ1 . "'><br />\n"; ?> To see the code in action: [*]http://www.maryellenoconnor.com/docs/silks.php [*]Refresh the page, then repeat, repeat ....
-
The goal is simple: I want to display "August 31, 2009" I RTFMed and tried various date functions. I got inconsistent results, so I did some "sanity check" tests. The results were better, but not completely as expected. Some returned Tuesday, August 18, 2009 15:08:45 Others returned Wednesday, December 31, 2008 00:12:01 <?php // php 5.2 $rightnow=$_SERVER['REQUEST_TIME']; $fmt= "l, F d, Y H:m:s"; // V $thev = mktime(0,0,1,08,31,2009); $dayv = date($fmt,$thev); // returned [b]Wednesday, December 31, 2008 00:12:01[/b] // W $thew = time(00,00,01,08,31,2009); $dayw = date($fmt,$thew); // returned [b]Tuesday, August 18, 2009 15:08:17[/b] (current time) // X $thex = time(); $dayx = date($fmt,$thex); // returned [b]Tuesday, August 18, 2009 15:08:17[/b] -- as expected // Y $dayy = date($fmt,$rightnow); // returned [b]Wednesday, December 31, 1969 16:12:00[/b] (!!!) // Z $dayz = date($fmt); // returned [b]Tuesday, August 18, 2009 15:08:17[/b] -- as expected ?> What is the correct syntax to display August 31,2009
-
[SOLVED] PHP code not fetching all values from mysql db
snorky replied to snorky's topic in PHP Coding Help
To quote myself (from the original post) "Somewhere in there I've missed a comma or some such stupid error that I can't see." First, an explanation. [*]The part that we have discussed is a small piece of a much larger project. [*]I try to build my code as modular as possible. I break down the big task into smaller tasks. The smaller tasks wind up as small scripts or in some cases, functions. The big task is handled as a 'home' page with a lot of included files. The report procedure was in an include that was included in an include. So the trees got in the way of my seeing the forest (to badly use a metaphor). While pondering replies (all very good, thank you), I realized I had been focused on the lower-level includes. What I had not examined closely: the home page and its first-level includes. The home page had an include that contained the query around which everything else is built. The person who requested this report did not want 'room' or 'fax' to appear. Mistake #1 was to remove those fields from the original query - instead of omitting them from the report. Mistake #2 was forgetting that that I removed them way up near the top level. When I looked at the original query way up there on the home page, clear as could be was the answer AND my comment about why those fields were omitted. du-oh! So I put 'room' and 'fax' back into the original query (and fixed the comment) ... and this report works! Thank you all. I learned a bunch of good stuff. And I got a concussion and waffle-like imprints on my face - from beating my head on the keyboard. :facepalm: The good news: the lady for whom I write a lot of stuff usually sends over something chocolate as appreciation for my work. I can hardly wait! -
[SOLVED] PHP code not fetching all values from mysql db
snorky replied to snorky's topic in PHP Coding Help
Number of rows : 914 Number of rows where room !="" : 747 Number of rows where room ="" : 167 Number of rows where room IS NULL: 0 Number of rows where FAX !="" : 58 Number of rows where FAX ="" : 0 Number of rows where room IS NULL: 856 However, none of those values impact the results of the mysql_fetch_array. In the report based on the result set for mysql_fetch_array, all rows come up empty for room and fax. -
[SOLVED] PHP code not fetching all values from mysql db
snorky replied to snorky's topic in PHP Coding Help
I don't understand what you're asking. The mysql query is SELECT id,lname,bldg,room, phone, fax,affil FROM main; It works as expected. All fields display all data (including room and fax). That means that all of the data in all of the fields are in the db. -
[SOLVED] PHP code not fetching all values from mysql db
snorky replied to snorky's topic in PHP Coding Help
As per your suggestion: printing directly from the mysql_fetch_array made no difference. -
[SOLVED] PHP code not fetching all values from mysql db
snorky replied to snorky's topic in PHP Coding Help
I changed mysql_fetch_array to mysql_fetch_assoc. It made no difference. The upside is that I learned about mysql_fetch_assoc, which I have never used (until now). Thanks. -
I have a mysql database and PHP code that are working great .... except that the code does not fetch the values from 2 of the fields. +---------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+---------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | lname | varchar(50) | YES | | NULL | | | bldg | varchar(50) | YES | | NULL | | | room | varchar(20) | YES | | NULL | | | phone | varchar(50) | YES | | NULL | | | fax | varchar(9) | YES | | NULL | | | affil | varchar(6) | YES | | NULL | | +---------+---------------+------+-----+---------+----------------+ /* fetch the data, one row at a time */ while($row=mysql_fetch_array($rpt1)) { $id= $row["id"]; $lname= $row["lname"]; $bldg= $row["bldg"]; $room= $row["room"]; $phone= $row["phone"]; $fax= $row["fax"]; $affil= $row["affil"]; /* then print the report */ echo "<tr> <td>" . $id . "</td> <td>" . $lname . "</td> <td>" . $bldg . "</td> <td>" . $room . "</td> <td>" . $phone . "</td> <td>" . $fax . "</td> <td>" . $affil . "</td> </tr>" ; } No matter what values are in "room" and "fax", the fetch _array does not fetch the values for those two fields in any row. It must be a "fetch" problem because I have tweaked the code to move items around. No matter what I do, it is only "room" and "fax" that are wrong (empty) and they are always wrong. I even tried commenting out the actual report and built a simple temporary report without the table and with only a few fields. Everything printed correctly except "room" and "fax" In the real report, all of the other data display as designed. The only errors are the missing data in those two fields. I'm looking for a 'sanity check.' Somewhere in there I've missed a comma or some such stupid error that I can't see.
-
I came up up with a way to get the desired result. It's kludgey, involving nested if-else statements. <?php // there are 3 possible values for $emdiff: // NULL, "" (blank), and (non-blank) if(isset($emdiff)) // if emdiff is NOT NULL { if($emdiff !='') // emdiff is NOT NULL and NOT blank { do task a; } else // emdiff is NOT NULL and is blank(empty) { do task b; } } else // otherwise, emdiff is NULL { do task c; } ?> If anyone can come up with a more elegant solution, I'd love to see it. I suspect that a switch/case would be better, but I struck out dozens of times trying.
-
In the above, The report looks fine (except that one column): all of the other elements of the report - including some generated by other switch statements (one of which has NULL as a possible value) - look as designed Should read The report looks fine (except that one column): all of the other elements of the report - including some generated by other switch statements (NONE of which have NULL as a possible value) - look as designed. That oopsie changes a lot.... sorry for the confusion.
-
/* ---------------------- */ The goal is to produce a report. There is a while loop that spins out the report based on what happens in the while loop. The report looks fine (except that one column): all of the other elements of the report - including some generated by other switch statements (none of which have NULL as a possible value) - look as designed. (Note: I changed :one" to NONE" - oops!) Here's how I got the variable where NULL is a possible value: The table has a column named emdiff. The PHP to produce the report is next: while($row=mysql_fetch_array($rpt1)) .... $emdiff= $row["emdiff"]; // note: there several other columns in this mysql_fetch_array // all of them work as designed - including switch statements - but none of them has a condition where NULL is one of the possible values // in the process, values are assigned to $var2 and $var3 .... Then the switch statement in question: switch($emdiff) { case * (where * is some kind of NULL -- see below): print ""; break; case "" print $emdiff . " abcdef"; break; case "!=''" print $var2 . $var3; break; } // end switch statement } // end while loop In the result set a. when $emdiff is NULL the field displays as designed (meaning: it displays an empty result) b. when $emdiff is ="" print $emdiff . " abcdef"; does not display, even though it should display c. when $emdiff is !="" print $var2 . $var3; displays as designed When I use the other attempts at case * (some expression of NULL), I get various mixes of a, b, and c
-
PHP 4.3.8 I can't figure out the correct syntax for the case condition in a switch statement where one of the case conditions is a NULL value. :facewall: For a switch statement I have 3 conditions: [*]variable's value is NULL // NULL [*]variable's value is "" // blank & NOT NULL [*]variable's value is "abcdef" // not blank (and therefore NOT NULL) The switch statement looks like this switch(var) { case * (where * is some kind of NULL -- see below): do something #0; break; case "" do something #1; break; case "!=''" do something #2; break; } * Case NULL is the joker in the deck. I've tried it 5 different ways. case "= NULL": case NULL: case "NULL": case IS_NULL(): case "IS_NULL()": None of the 5 works correctly when the condition is a NULL value. Each of those has a different -- and incorrect -- result set for variable's value is NULL // NULL variable's value is "" // blank & NOT NULL variable's value is "abcdef" // not blank (and therefore NOT NULL)
-
There are several forms and reports that use the same database. One of the forms is where users can make edits the the database, and only few trusted users can access it. The people who use the data for reports don't see the 'pick list' in question. However, I solved the problem AND made the menu slicker by coding in a list that is dynamically generated when the form is opened. The code for that page does a SELECT DISTINCT ... ORDER BY... on the field in question, uses a foreach loop, and spins out a <SELECT><OPTION> menu that is always current. If there is a need for a new value to add to the list, there's a field in the form that enables adding a new value (as huku suggested above). Once that form posts, the next time someone accesses that page, they'll get the latest version of the menu. The menu is a no-maintenance item for me (I don't have to go into the code to add or delete items from the list). Back to the read-only people .... they use a form to select the criteria for the report that they want to see. I could give them the same pick list (read only), but with 35 or so items (and growing), it's unwieldly. Instead I give them a text field to enter the criteria, and evaluate their entries by using a SELECT ... FROM ... WHERE ... LIKE "%nnnn%" ... ORDER BY statement. That's my "Horseshoes" code. It counts even if they're close. Examples: User wants to see a list of custodians, but can't spell 'custodian'. The pick list would by way too long, e.g., 35 items. but if the user enters 'cust' in the test box, they'll get a list of custodians and customers. If the report is too long, the user can see how to spell 'custodian', and enter that to narrow the search. If the user enters 'sec' the user gets a list of secretaries and section_leaders. 'uperv' gets the supervisors and so on. Everyone seems happy with the program.
-
THX. I tried your auxiliary text box idea. It works great. And less filling....