phpstuff
-
Posts
107 -
Joined
-
Last visited
Posts posted by phpstuff
-
-
Do you guys think I should just switch to MAMP? Is that more common?
So, I just went into Terminal, and tried:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
And got errors:
-bash: mysql_tzinfo_to_sql: command not found
-bash: mysql: command not found
And to Larry's point above, I did navigate into the zoneinfo folder and used "ls" to list the contents and there was nothing except:
+VERSION CST6CDT Europe Hongkong MST Poland W-SU
Africa Canada Factory Iceland MST7MDT Portugal WET
America Chile GB Indian Mexico ROC Zulu
Antarctica Cuba GB-Eire Iran Mideast ROK iso3166.tab
Arctic EET GMT Israel NZ Singapore posixrules
Asia EST GMT+0 Jamaica NZ-CHAT Turkey zone.tab
Atlantic EST5EDT GMT-0 Japan Navajo UCT
Australia Egypt GMT0 Kwajalein PRC US
Brazil Eire Greenwich Libya PST8PDT UTC
CET Etc HST MET Pacific UniversalSo I can navigate to the zoneinfo folder, but the command "mysql_tzinfo_to_sql" is not working for some reason.
-
I just tried to change the timezone and got this below:
#1298 - Unknown or incorrect time zone: 'America/Los_Angeles' SET time_zone = 'America/Los_Angeles'
and...
CONVERT_TZ('2012-06-07 12:00:00', 'GMT', 'America/New_York')
NULL
-
Yes, mysql starts from the terminal fine without problems.
-
That's the problem...I don't even know where that directory is found.
Where is it found? Under XAMPP?
The only thing I've found remotely close is:
Applications / XAMPP / xamppfiles / bin / mysql_tzinfo_to_sql
I added an empty folder on my desktop called "zoneinfo" and then searched for it with Finder and it came up in the search results..so i'm not sure that anything with that name is on my computer.
Supposedly since its Mac OSX it should have it already and should not need that installation package but so far I can't find anything.
-
And here are the errors I receive:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near './mysql_tzinfo_to_sql /usr/share/bin/zoneinfo | ./mysql -p -u root mysql' at line 1
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql' at line 1
-
Per the sidebar on page 190 (ch. 6) of this book I attempted to populate the tz tables using the sample code provided on the MySQL site:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
After that didn't work, I browsed around on this site, Stackoverflow and a few other sites, and cannot figure this out.
Here on this site the closest thing I could find was:
I used that code and it didn't work - maybe the directory path is off? I'm not sure... Xampp is running. I went to the finder and searched for "zoneinfo" and found nothing...
On Stackoverflow the user said he had to use a Linux box to create the file and then copy it to his Mac, but that doesn't sound right:
http://stackoverflow.com/questions/17914284/mysql-convert-tz-command-returns-null
Any help or direction here is appreciated...
-
Sounds good and that makes sense - thanks for your help and reply!
-
I've since quit using Terminal and have been using phpmyadmin with no issues.
If I have both PMA and Terminal open simultaneously would that screw up anything?
-
Thanks for the reply. I was having some issues getting this to work and the major issue was just not hard coding the new password into the PMA config file. At this point I'm comfortable with this and was more or less leaving it up in case it can help somebody else.
-
Sure here is all the code below. There is an error towards the bottom (George Harrison) I did find, but, as you'll see after that I corrected it (it was missing 1 parenthesis on the NOW ). Maybe you can find something. Maybe restart everything??
mysql> use sitename; Database changed mysql> CREATE TABLE users ( -> user_id MEDIUMINT UNSIGNED NOT NULL -> AUTO_INCREMENT, -> first_name VARCHAR(20) NOT NULL, -> last_name VARCHAR(40) NOT NULL, -> email VARCHAR(60) NOT NULL, -> pass CHAR(40) NOT NULL, -> registration_date DATETIME NOT NULL, -> PRIMARY KEY (user_id) -> ); Query OK, 0 rows affected (0.03 sec) mysql> SHOW TABLES; +--------------------+ | Tables_in_sitename | +--------------------+ | users | +--------------------+ 1 row in set (0.00 sec) mysql> SHOW COLUMNS FROM users; +-------------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+-----------------------+------+-----+---------+----------------+ | user_id | mediumint(8) unsigned | NO | PRI | NULL | auto_increment | | first_name | varchar(20) | NO | | NULL | | | last_name | varchar(40) | NO | | NULL | | | email | varchar(60) | NO | | NULL | | | pass | char(40) | NO | | NULL | | | registration_date | datetime | NO | | NULL | | +-------------------+-----------------------+------+-----+---------+----------------+ 6 rows in set (0.01 sec) mysql> INSERT INTO users -> (first_name, last_name, email, pass, registration_date) -> VALUES ('John', 'smith', 'johnsmith@yahoo.com', SHA1('testpassword'), NOW()); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO users VALUES -> (NULL, 'Zoe', 'Isabella', 'email2@example.com', SHA1('mojito'), NOW()); ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 44 Current database: sitename Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('lefITbe'), NOW()), -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW(), -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW()); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5 mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()), -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()), -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW()); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul'' at line 1 mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHAe) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()), ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()), ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW()); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul'' at line 1
-
I entered in the below code into terminal and got the error below in red. Not sure where the error is? I double checked it but operating on minimal sleep so maybe a dumb error...
INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()), ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()), ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul'' at line 1 -
Actually, Appendix A doesn't mention what I found on another site:
Can somebody confirm/deny what this guy is saying on another forum with regards to making a change to the code below?
by hackattack142 » 31. May 2013 03:24
You should not be putting passwords in my.ini
As for config.inc.php, if you want to use the password in this config file, you need to change this:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
from 'cookie' to 'config' -
***I Figured this out but couldn't figure out how to delete this post so I'm leaving it here (should have read Appendix A - pg A9 more carefully ****
So I was using phpmyadmin just fine until it was recommended to change the root PW. I changed the PW and then when I try to re-access PMA it tells me the below. It appears the passwords are conflicting some how - like it thinks it still has no password even though I added a new pw. When I followed the directions in Appendix A to change the PW via Terminal it didn't work, so I used PMA to change the password and it worked. I believe I changed the PWs for both "localhost" and "user" but can't remember since I'm now locked out.
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.From Appendix A if you are having this same problem as above, just open the config.inc.php file for phpmyadmin and below where it shows = "" just enter your new password inside the quotes (eg, "testtesttest").$cfg['Servers'][$i]['password'] = '';
-
Thank you for your very detailed reply HartleySan - greatly appreciated once again! I will investigate that link.
-
Very Cool! Thank you both for your time in your responses. I am more a designer and just now seriously getting into PHP so I have knowledge about front end optimization, but, you are right it might make sense to focus more on front end (image optimizing, sprites, etc - I've seen that yahoo site before and should revisit it). I've never heard of "Big-O" analysis so I will look into that further. Thanks again for your help!
Actually, you sparked one last question regarding image optimization which is obviously important. Lets say a site I have planned calls for users to upload photos - how do you best optimize the photos with PHP? I have heard of and briefly read up on image processing before but I'm not sure what the "good programmers" use when looking to efficiently upload and compress photos for faster browser retrieval/loading. I understand PHP can do this - any tips/tricks you can share here?
-
Can somebody provide a general overview of how to code with site performance in mind (memory, CPU usage, calls to DB, etc)? If this isnt a good conversation to post here can somebody please add some links that I can follow out and learn more?
For instance, from my studies so far and general knowledge:
1. Obviously less characters creates smaller file sizes.
2. Creating user defined functions eat memory, but there is some "tipping point" where they become a performance improvement vs. a burden - how do I objectively determine this?
3. Creating templates for Header / Footer is probably a good idea for cleaner code and ease of use, but will I gain any (even if its .5%) performance if the Header/Footer is hard coded to every page? Wouldn't the browser cache specific components to help performance and place the burden on the user's computer rather than the server?
4. I read this book through before running back through again and completing the tuts (now on Ch. 4). I remember seeing lots of tips for MySQL performance - what is the best resource for really exploring MySQL performance, and is it worth the time to tweak the MySQL DB with all the talk about the NoSQL DBs being so much faster?
5. Any other ideas, sites, links for PHP and MySQL performance?
Thanks!
-
How would I check which databases have been created - can I somehow call a list of all created databases? I'm not sure where that is "stored".
-
I coded all for Ch 13 and went to run through everything and I'm having DB related errors pop up. I provided the latest below. At first I thought I had the mysql_connect_ch13.php script setup wrong with regards to directory location. In my htdocs I have all the main files for ch13, the header/footer template files in templates folder (works fine), and functions_ch13.php in the includes folder(works fine too I believe). When I call the mysql_connect_ch13.php, I have it listed as a file by itself without dots or slashes which I believe is correct (I didn't put it in a different directoy than all the other scripts to keep things simple for now). As you see below the issue is with the script not recognizing a DB. I went through all scripts and made sure that I called the DB "myquotes" everywhere. I also think that I called the table "myquotes" for simplicity. I ran the create_db_ch13.php script more than once thinking that the first time I created a DB named "quotes" and not "myquotes." Anyways if anybody sees anything that sticks out please let me know, otherwise I'll probably just start from scratch on this chapter as well... Thanks!
My Site of Quotes
Add a QuotationCould not store the quote because:
Table 'myquotes.myquotes' doesn't exist.The query being run was: INSERT INTO myquotes (quote, source, favorite) VALUES ('This is a test quote', 'someguy', '1')
Quote
Source
Is this a favorite?
Site AdminAdd Quote <-> View All Quotes <-> Logout
Content © 2013<!DOCTYPE HTML> <html> <head> <title>Create the database</title> </head> <body> <?php //Script 13.0 - create_db_ch13.php //This script connects to the MySQL server, creates and selects the database. //Attempt to connect to MySQL and print out messages: if ($dbc = @mysql_connect('localhost', 'root', '')) { print '<p>Successfully connected to MySQL!</p>'; // Try to create the database if (@mysql_query('CREATE DATABASE myquotes', $dbc)) { print '<p>The database has been created!</p>'; } else { //could not create it print '<p style="color: red;">Could not create the database because:<br />' . mysql_error($dbc) . '.</p>'; } // Try to select the database: if (@mysql_select_db('myquotes', $dbc)) { print '<p>The database has been selected!</p>'; } else { // could not select it print '<p style="color: red;">Could not select the database because:<br />' . mysql_error($dbc) . '.</p>'; } mysql_close($dbc); //close the connection } else { print '<p style="color: red;">Could not connect to MySQL:<br />' . mysql_error() . '.</p>'; } ?> </body> </html>
<?php // Script 13.7 - add_quote_ch13.php // This script adds a quote // Define a page title and include the header define('TITLE', 'Add a Quote'); include('templates/header_ch13.html'); print '<h2>Add a Quotation</h2>'; // Restrict access to only Administrators if (!is_administrator()) { print '<h2>Access Denied</h2> <p class="error">You do not have access to this page.</p>'; include('templates/footer_ch13.html'); exit(); } // Check for a form submission if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ( !empty($_POST['quote']) && !empty($_POST['source'])) // Need the database connection (script) ======== IS THIS THE CORRECT DIRECTORY STRUCTURE? include('mysql_connect_ch13.php'); // Prepare the values for storing $quote = mysql_real_escape_string(trim(strip_tags($_POST['quote'])), $dbc); $source = mysql_real_escape_string(trim(strip_tags($_POST['source'])), $dbc); // Create the "favorite" value (if box is checked then it = 1) if (isset($_POST['favorite'])) { $favorite = 1; } else { $favorite = 0; } $query = "INSERT INTO myquotes (quote, source, favorite) VALUES ('$quote', '$source', '$favorite')"; $r = mysql_query($query, $dbc); if(mysql_affected_rows($dbc) == 1) { // Print a message print '<p>Your quotation has been stored.</p>'; } else { print '<p class="error">Could not store the quote because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // Close the connection mysql_close($dbc); } else { // Failed to enter a quotation print '<p class ="error">Please enter a quotation and a source.</p>'; } // End of submitted IF // Leave PHP and display the form ?> <form action="add_quote_ch13.php" method="post"> <p><label>Quote <textarea name="quote" rows="5" cols="30"></textarea></label></p> <p><label>Source <input type="text" name="source" /></label></p> <p><label>Is this a favorite? <input type="checkbox" name="favorite" /></label></p> <p><input type="submit" value="Add this quote!" /></p> </form> <?php include('templates/footer_ch13.html'); ?>
<?php // Script 13.11 - index_ch13.php /* This is the homepage for the site. It displays: - The most recent quote (default) - OR, a random quote - OR, a random favorite quote */ //Include header include('templates/header_ch13.html'); //Need DB connection include('mysql_connect_ch13.php'); //Define the query //Change the particulars depending upon values passed in the URL: if (isset($_GET['random'])) { $query = 'SELECT quote_id, quote, source, favorite FROM myquotes ORDER BY RAND() DESC LIMIT 1'; } elseif (isset($_GET['favorite'])) { $query = 'SELECT quote_id, quote, source, favorite FROM myquotes WHERE favorite=1 ORDER BY RAND() DESC LIMIT 1'; } else { $query = 'SELECT quote_id, quote, source, favorite FROM myquotes ORDER BY date_entered DESC LIMIT 1'; } //Run the query if ($r = mysql_query($query, $dbc)) { //Retrieve the returned record: $row = mysql_fetch_array($r); //Print the record print "<div><blockquote>{$row['quote']}</blockquote>- {$row['source']}"; // Is this a favorite? if ($row['favorite'] == 1) { print ' <strong>Favorite</strong>'; } // Complete the DIV print '</div>'; // If the admin is logged in, display admin links for this record: if (is_administrator()) { print "<p><b>Quote Admin:</b> <a href=\"edit_quote_ch13.php?id={$row['quote_id']}\">Edit</a> <-> <a href=\"delete_quote_ch13.php?id={$row['quote_id']}\">Delete</a> </p>\n"; } } else { //Query didn't run. print '<p class="error"<Could not retrieve the data because:<br />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // End of query IF. mysql_close($dbc); //Close the connection print '<p><a href="index_ch13.php">Latest</a> <-> <a href="index_ch13.php?random=true">Random</a> <-> <a href="index_ch13.php?favorite=true">Favorite</a></p>'; include('templates/footer_ch13.html'); // Include the footer ?>
<?php // Script 13.1 - mysql_connect_ch13.php // This script connects to, and selects the database // Connect and select: if ($dbc = @mysql_connect('localhost', 'root', '')) { // Handle the error if the database couldn't be selected: if (!@mysql_select_db('myquotes', $dbc)) { print '<p style="color: red;">Could not select the database because:<br />' . mysql_error($dbc) . '.</p>'; mysql_close($dbc); $dbc = FALSE; } } else { // connnection failure print '<p style="color: red;">Could not connect to MySQL:<br />' . mysql_error() . '.</p>'; } ?>
-
I ended up scrapping everything (code) and starting over at the beginning of the chapter, and I'm glad I did - everything made more sense the second time around. 1 more chapter to go (working on it now!) then off to PHP and MySQL for dynamic websites.
-
Sorry about the confusion. Actually the code from Script 12.5 is what should be in there, but the code in Script 12.6 as written will work, too. The Script 12.5 approach is just cleaner, is all.
Thank you for your reply Larry.
-
To add detail, PHP has a series of global arrays for HTTP request. $_POST is filled with POST data, $_GET with GET and $_REQUEST is a combination of them both. $_REQUEST is thus the least explicit of them of them all, and that's why you need to check if the request method is POST first. When you deal with just POST request, ($_POST) you already know that. It is therefor considered "cleaner" or more specific.
Thank you for the further explanation of the above.. Makes sense now! Appreciate it.
-
Not a big deal just thought I'd point it out:
(when the user clicks the link in view_blog.php, see C in the previous section)
Should instead read:
(when the user clicks the link in view_entries.php, see C in the previous section)
-
So I wrapped up 12.6, 12.7, 12.8 and went to try out and test and had some issues.
I found an error and fixed it in the code to where I could get the "delete post" to work. My "edit post" part isn't working however.
I started looking at the code and comparing in the book, and then noticed that 12.5 (pg 353) and 12.6 (pg 359) code mysteriously changed where it shouldn't have changed:
12.5 code:
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Handle the form
When you get to 12.6 (pg 359) it only says that the "mysql_real_escape_string"portions should be changed, however the code on 12.6 changes to (on the same line):
if (isset($_POST['submitted'])) { //Handle the form
Why did this change and which version is correct?
Will this make the "edit post" link not work?
-
Ahh.. got it! Nice hint thank you very much!
I'll be wrapping up this book in the next week or so and then I'll be on to PHP and MySQL so I'm sure this won't be the last you hear from me!
Appreciate the help once again truly..
Ch. 6 - Loading Timezone Data Into Tables - Help Needed
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
Ok......so from my post above the file is here:
Applications / XAMPP / xamppfiles / bin / mysql_tzinfo_to_sql
I navigated via terminal to the bin folder, and attempted to run:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
And still got errors:
-bash: mysql_tzinfo_to_sql: command not found
-bash: mysql: command not found