Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi there - the most hated problem has occurred (for amateurs at least)

 

can't connect to database message

An error occurred in script '/hermes/waloraweb004/b1384/moo.laissezfairelondonco/wolfcut.co.uk/views/home.html' on line 14:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

 

 

index.php line 14

// Require the database connection:

require ('../mysql.inc.php');

 

 

folder structure

mysql.inc.php (outside web root)

 

beans (folder) --------- > index.php (with the error message)

                       --------- > billing.php

                       --------- > browse.php

                       --------- > etc...

 

 

Link to comment
Share on other sites

This is because you have a syntax error in one of your queries. mysqli_result() return a MySQLi_result object (or resource) on successfully query, and a boolean false on errors. As mysqli_num_rows() expect that resource/object, you'll get that error message you display here.

 

Try debugging it by printing out the query, make sure your variables holds values, and that kind of stuff. Running the query in something like phpMyAdmin is also helpful.

  • Upvote 1
Link to comment
Share on other sites

Hello Again Antonio - what would I do without you.

 

The variable:

 

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

 

seems to be the only thing returning an error.

 

Will you cast an expert eye over the error message printed out at:  www.wolfcut.co.uk

Link to comment
Share on other sites

Well well, I have been going round the blocks trying work out how to put this Stored Procedure into PHPMYaDMIN, and have been at loggerheads as to what is "Create Routines" permissions with the hosting company.

 

For example, I am trying to do this (page 201) in the SQL box:

 

 

DELIMITER $$
CREATE PROCEDURE remove_from_wish_list (uid CHAR(32), type VARCHAR(6), pid MEDIUMINT)
BEGIN
DELETE FROM wish_lists WHERE user_session_id=uid AND product_type=type AND product_id=pid;
END$$
DELIMITER ;

 

 

 

But all I keep getting is this error:

 

 

 

 

Error

SQL query:

DELIMITER $$ CREATE PROCEDURE remove_from_wish_list( uid CHAR( 32 ) , TYPE VARCHAR( 6 ) , pid MEDIUMINT ) BEGIN DELETEFROM wish_lists WHERE user_session_id = uid AND product_type = TYPE AND product_id = pid;
 

MySQL said: b_help.png

#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 'DELIMITER $$
CREATE PROCEDURE remove_from_wish_list (uid CHAR(32), type VARCHAR' at line 1 

Link to comment
Share on other sites

nope - that didn't work either Please see this:

in the meantime I am still waiting for my hosting provider to get me about this "Create Routines" permissions as mentioned in the "big man's" book.

 

 

 

Error

SQL query:

DELIMITER $$;
 

MySQL said: b_help.png

#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 'DELIMITER $$' at line 1 

Link to comment
Share on other sites

Ok. Hope you get that sorted.

 

My last suggesion is totTry switching delimiter to something like "DELIMITER //;" instead. I've seen some code use that. You must also change it from "end$$" ot "end //" too if you try that. I've also seen people comment that not using a space in for example "end$$" might be a problem.

 

Guess we just have to wait for Larry on this one. Sorry I couldn't really help.

Link to comment
Share on other sites

I can't believe it but my hosting provider Fatcow doesn't support stored procedures!

I am truly snookered because I can't proceed further with the exercises in the book and a quick trawl online shows it will cost an arm and a leg to join a hosting company that supports stored procedures.

 

There must be another way around this, I should reall post this under a different heading really.

Link to comment
Share on other sites

Just save it as a normal query. Stores procedures can be nice, but I've generally never used them. I generally prefer not to use stored procedures.

 

If it's important for you to learn this, hit me a personal message. I can lend you a Db for a couple of weeks. If you really need it for production, I guess that just sucks. You'll defiantly find a workaround in most cases though.

Link to comment
Share on other sites

Anotonio, are Nowegians always this kind? I really appreciate your call, and if you were in London I would pat you on the back and buy a Heineken.

 

I do want to learn this thoroughly with a view to designing a really cool website. So what I want to do in this case is research another host: (HostGator; iPage; DreamHost; Go Daddy, etc) and at the same time find out how to convert stored procedures to standard PHP MySql, which I will set up a new post for, because my original problem has now escalated to level 10!!

 

Thanks, Best Regards, London, UK

Link to comment
Share on other sites

Ohio Gozaimasu!!!

 

I will take your inspiration and start looking into prepared statements. The question is, without guidance from a book I'm not sure how to enter anything I learning into the set of scripts in Larry's ecommerce book - did you have to do this?

 

Arigatou

Link to comment
Share on other sites

To be honest, I think stored procedures look way scarier than prepared statements. When you get it down, it's very simple and logical. Reading a simple guide from something like NetTuts should teach you how to use them quite quickly.

 

Not really a problem. I just bought new hosting for my website, so I have plenty of everything. I guess installing Xampp or something would really let you test the same way, but I could lend you some space if needed. I can lend you FTP access, a subdomain and a DB for a month if you want to test a live environment before you buy anything.

Link to comment
Share on other sites

research another host: (HostGator; iPage; DreamHost; Go Daddy, etc)

If you do decide to go with another host, think twice about switching to Go Daddy. The support is not great and I found updating my site very slow (also the ads they ran during the super bowl were so appalling that it is reason enough to boycott them :)). I have since switched to csn-uk who are brilliant on support and not expensive. But if you're outside the uk they may not be a good option.

 

I think stored procedures look way scarier than prepared statements

Totally agree. Its worth learning prepared statements even if you get the stored procedures working. They're better for security and performance, particularly if you're running the same query multiple times.

 

Prepared statements basically involve 3 steps

  1. prepare the statement by defining the placeholders to be used in your query. Placeholders indicate the places where variables will be provided at run time. A simple SELECT statement "SELECT * FROM users WHERE username='$un' && password='$pw'  becomes "SELECT * FROM users WHERE username = ? && password =?). Question marks are the placeholders for the variables you will bind in the next step. So first you prepare the statement with
    $statement = mysqli_prepare($dbconnection, $query );
    

     

  2. bind the parameters to the statement

    mysqli_stmt_bind_param($statement, 'ss', $un, $pw);
    

     

    The second paramenter lists in order the variable types of the parameters to be bound - in this instance I am binding 2 strings. For a more lengthy query you might get something like ssiisss - that would indicate you are binding 7 variables 2 strings then 2 integers then 3 strings. (Other variable types are supported.) The last parameters, again in order, specify the variables to be bound.
  3. execute the statement -
    mysqli_stmt_execute($statement); 
    

     

 

 

Link to comment
Share on other sites

nope - that didn't work either Please see this:

Error

SQL query:

DELIMITER $$;

 

MySQL said: b_help.png

#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 'DELIMITER $$' at line 1 

You are using semi-colon instead of colon.

 

Also, if you pick new host search this forum for suggestions.

Link to comment
Share on other sites

Dear All -- last nights support was awesome!

I have found the questions to my answers and here they are:

 

 

 

CHAPTER 8 ALTERNATIVE TO STORED PROCEDURES = shop.php / browse.php / sales.php / index.php
 
CHAPTER 9 ALTERNATIVE TO STORED PROCEDURES = cart.php / wishlist.php
 
CHAPTER 10 ALTERNATIVE TO STORED PROCEDURES = checkout.php / billing.php / final.php
  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...