Jump to content
Larry Ullman's Book Forums

Lou

Members
  • Posts

    97
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by Lou

  1. 1. What version of PHP are you using? If you're using PHP 4 you can't use the mysqli functions. But since you're on a Windows 7 laptop, I don't think you'd be using PHP 4.

     

    2. Can you sign into phpMyAdmin with the username and password you say you checked and are correct?

     

    3. Run the mysqli_connect.php script by itself and see if you can connect. If it's stored in the includes folder, just type the URL out, ending with the mysqli_connect.php script. For example...

     

    http://localhost/sitename/includes/mysqli_connect.php
    

  2. You need to actually execute the query.

     

    $insert = mysqli_query($dbc, $query);
    

     

    Your query is not correct though. Follow the previous person's advice and fix that query. I like to run my queries through the mysql monitor or phpmyadmin before trying it in php code. That may help you out.

     

    You also don't have to run that mysqli_select_db function, you already selected the database in your mysqli_connect function.

    • Upvote 1
  3. Larry,

     

    I'm more than half way done with this book. After initial problems (mainly because I haven't used DOS style commands in awhile) I'm really enjoying this edition.

     

    I had no idea you could connect to MySql with Perl or Java. Even though I'm not going to really use these languages, I'm giving it a shot. One question -- Can you use Perl to connect to the database, but then use PHP to do everything else? Do you ever use Perl/Java for connecting, or do you mainly use PHP?

     

    Thanks again.

  4. the code on page 43 to change the root password does not seem to work anymore. Probably because the book is old. But...

     

    You have listed to change the root password via mysqladmin...

     

    bin\mysqladmin -u root password 'thenewpassword'

     

    The quotes cause a problem when creating the new password, as single quotes aren't trimmed, so your new password will include the single quotes

     

    This works

     

    bin\mysqladmin -u root -p password thenewpassword

  5. thanks Paul... I've been using PHPMyAdmin for about a year, but to learn SQL better, I've been trying to use the command line for many things. I'm actually connecting MySQL through PDO (upgraded from mysqli procedural) but I just couldn't figure out what was going on in the command line client.

     

    When you put it the way you did, that -u username is not SQL, it makes perfect sense. I was just assuming that the command line client would work the same way as all the examples in Larry's 2nd edition, and the 5 other MySQL books I have.

     

    This leads me to another question. When you start the command line client, how do you start it with another user other than root, or is that not possible?

     

    Thanks very much for your clear explanation previously!

  6. I can get in and change the user if I use cmd on windows 7. I can sign in as root, larry, basic, all of my users.

     

    However when I use the mysql command line client (start/all programs/zend server/mysql server 5.1/command line client) I simply cannot change users and it logs me in as root automatically, and when i enter the SQL to change the user, I get a syntax error.

     

    It seems that the mysql command line logs me in as root, and there's no way i can change users because i can't get back to the bin directory. When I use CMD, when i enter exit i am taken back to bin, where i can change users to root or one of the basic users i created....

     

    anyone have any ideas?

  7. Try:

    mysql -u larry -p

    The host name is optional. Are you getting prompted for the password?

     

    And what is the full error? MySQL generally tries to tell you approximately where in your statement it is detecting an error.

     

    still doesn't work. says:

     

    you have an error in your sql syntax... check the manual near 'mysql -u larry -p' at line 1. no matter what i do, i get this error. i created another user in phpmyadmin that has select, insert, update, and delete privileges on a certain database, say... larry.

     

    in the mysql monitor, before i try to change the user to larry, i make sure to show databases, and then use the larry database.

     

    any attempt to then change the user to the one i created results in this syntax error in the mysql monitor.

  8. Pinning the icon to the taskbar just means that the icon to start the program is always there at the bottom of the desktop instead of going through Start/Programs.

     

    Another question... how do I login as a different user with the MySQL monitor? When I start it up, I can only enter the root password. I've set up the root user and the louis user through phpmyadmin. the louis user can only insert, update, select, and delete. i'd like to sign in as this user through mysql monitor, but don't see how to do it. using commands like -u louis -p -h localhost; does nothing. I'm completely confused. Do I have to change directories as it mentions in your book? I don't think so, because the top of the mysql monitor says it's already in the properl directory that mysql.exe is located.

  9. I've been experiencing some kind of bug with the MySQL monitor. I'm using Zend Community Server on Windows 7. PHP 5.35, MySQL 5.1.50.

     

    It seems that when I open the MySQL monitor, sign in as root, then pin the icon to my taskbar, if I ever exit the MySQL program with the exit command, when I click the taskbar icon again to open it, I'm still signed in, but as "odbc@localhost" and lose access to my databases. There's no way to sign out from this, either.

     

    Has anyone experienced this or know why it happens? I usually use PHPMyAdmin, but I'm learning to type all my commands in as well.

  10. Hi Stuart.

     

    Yes, I used the date() function. I still couldn't get it to work. I'm sure there's a way to do it with that method though, I'll try your suggestion.

     

    But, I have gotten it to work by using some SQL functions. This works.

     

    $select_poll = "SELECT P.poll_id, P.question, A.answer_id, A.answer FROM poll_questions P 
    INNER JOIN poll_answers A ON p.poll_id = A.poll_id 
    WHERE date = (SELECT DATE_FORMAT(NOW() ,'%Y-%m-01'))";
    

     

    Each poll question has a date column and I store the first date of the month in it... 2011/08/01, 2011/09/01, 2011/10/01. When the new month starts, the new poll and answers are shown.

  11. I've almost completed my poll item, but I'm struggling putting the finishing touches on it.

     

    Basically, I'm storing polls, answers, and votes in MySQL. The polls table has the poll_id, question, and date. The answers table has the answer_id, poll_id, answer, and votes.

     

    I have everything automated except when to show a particular poll. During August 2011 I want to show one poll along with it's question and answer choices. During September 2011, another. In the polls table I have a column called date that is type date. It stores dates in the format 2011-08-01 (year-month-day). I thought about making a variable that stores the current date in the same format. However when I put this variable in my query (since the variable will always change based on the current date) I get errors because the query expects the date string to be '2011-08-01', not 2011-08-01, without the quotes.

     

    I store every date as Year-Month-FirstDayofMonth... 2011-08-01 for August's poll... 2011-09-01 for September's poll

     

    I store the current date (2011-08) for Year-Month plus '01' for the first day of the month like this:

    $current_poll = ('Y' . "-" . 'm' . "-" . '01');

     

    However when I put $current_poll in the query I always get errors because it expect the string to be surrounded in quotes.

     

    Here's my working query with the date hard coded.

     

    $select_poll = "SELECT P.poll_id, P.question, A.answer_id, A.answer FROM poll_questions P 
    INNER JOIN poll_answers A ON p.poll_id = A.poll_id WHERE P.date = '2011-08-01'";
    

     

    I want the date to be automated so when it's September 1, the poll with the date 2011-09-01 shows.

    So I'm stuck... Is there an easier way to do this?

×
×
  • Create New...