Help with php/MySql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

herm....guess mysql and mysqli do have differences;) i normally omit the connection. i say remove storing your connection in a variable and put it on it's own line and forget the connection in the query, just do the query:-D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Charles256 wrote:herm....guess mysql and mysqli do have differences;) i normally omit the connection. i say remove storing your connection in a variable and put it on it's own line and forget the connection in the query, just do the query:-D
Yeah, I usually use a DB class, similar to phpBB's Database Abstraction Layer, so using the connection link is done behind the scenes. But I agree, the PHP core developers seem to like to keep us developers guessing with their parameter arrangements and function arguments. Oh well, I guess that is the price you pay for something as cool as PHP that is free and open.
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Hmm...

Post by dallasx »

Wouldn't it just be easier to use the mysql functions instead of mysqli functions?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hmm...

Post by RobertGonzalez »

dallasx wrote:Wouldn't it just be easier to use the mysql functions instead of mysqli functions?
I suppose it procedurally. But if you wanted to utilize the OOP style then you would have to either write a mysql class, download one or use mysqli. Seeing as the development world is streaming toward OOP it makes sense to get used to using an OOP style for development. This is of course just my opinion. There are still many times that I develop procedurally instead of OO.
User avatar
colorproof
Forum Newbie
Posts: 9
Joined: Fri Oct 21, 2005 12:38 pm
Location: Oregon

Post by colorproof »

Thanks for all the help guys, I really appreciate it.

Everah, when I used your code, I got this error:

Code: Select all

Parse error: parse error, unexpected '{' in /home/virtual/site222/fst/var/www/html/php/results.php on line 26
I used the original code straight from the book without any modifications (with the exception of using my own login/password and database name) so theoretically, it should work fine. The PHP version on my server should support mysqli so I don't know what is wrong. I could write it procedurally, but the book that I am working from, "PHP and MySQL Web Development" builds off this Book-O-Rama script in the continuing chapters into more complexity. I would like to continue with OOP than use procedural.

Charles, did you get a chance to test the script on your server at all?
User avatar
colorproof
Forum Newbie
Posts: 9
Joined: Fri Oct 21, 2005 12:38 pm
Location: Oregon

Post by colorproof »

Everah,

I realized that a end parenthesis was dropped from the first line:

Code: Select all

if(!$connect = mysql_connect('localhost', 'username', 'password'))
  { 
    die("Could not connect to the database server: " . mysql_error()); 
  }
after I added that, the script worked!!! YAY!!! Thanks Everah!!!
User avatar
colorproof
Forum Newbie
Posts: 9
Joined: Fri Oct 21, 2005 12:38 pm
Location: Oregon

Post by colorproof »

Ok, I figured out why the mysqli didn't work... turns out that my server DOESN'T support mysqli as I had previously thought. Thanks for everyone's help though, I am so grateful that all of you took time out of your day to help out a newbie such as myself. I hope I can return the favor sometime in the future!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

colorproof wrote:Ok, I figured out why the mysqli didn't work... turns out that my server DOESN'T support mysqli as I had previously thought. Thanks for everyone's help though, I am so grateful that all of you took time out of your day to help out a newbie such as myself. I hope I can return the favor sometime in the future!
I sort of thought that in the beginning, but I wanted to give your host the benefit of the doubt, hence the use of procedural mysql functions. Had the mysql functions not worked then you'd have been in deep soup. With them working it would lead me to believe that PHP wasn't handling the mysqli functions for some reason.

I am glad that I was able to help. When I started developing in PHP I leaned heavily on many members of this community (Feyd is an absolute master and timvw is the PHP manual incarnate). Hope I have the opportunity to help you again someday.

Take care and happy PHP'ing.
Post Reply