MysqlI and php5 under IIS rows returned=0 ??? [-Solved-]

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

Post Reply
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

MysqlI and php5 under IIS rows returned=0 ??? [-Solved-]

Post by Alex-Grim »

OK, here goes, i am an asp.net developer, trying to move over to non-os-proprietary scripting, databases, etc.
I currently have a HUGE website (group od sub-d's) under IIS, and i am TRYING to build a replica using the PHP-MySQL cofig, but i downloaded Mysql5 and PHP5, something i am finding out is not to good of an idea.
I have tried several examples of scripts for the mysqlI functions to no avail, i can CONNECT, but my queries return nothing. and yes, i AM connecting to a database that does have data (18,945 rows of it).

here's what i've got, and it does nothing:

Code: Select all

<?php
$link = mysqli_connect("localhost", "root", "DEMIGOD", "alexgrim");

if (mysqli_connect_errno()) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

if ($result = mysqli_query($link, "SELECT uname FROM account_info ORDER BY Name")) {
   $row_cnt = mysqli_num_rows($result);
   printf("Result set has %d rows.\n", $row_cnt);
   mysqli_free_result($result);
}

mysqli_close($link);
?>
at the moment i only have one pc, so i have to build this replica site under IIS, that way as soon as i get it working, i'll only have to take the site down for a short amount of time to switch it to apache, but right now, i HAVE to develop under iis so that the rest of my LIVE sites are running. but i don't think it has anyhting to do with iis at all because the script is working and interacting with the database, i just can't find the proper sytax or some crap.
Last edited by Alex-Grim on Mon Dec 26, 2005 11:51 pm, edited 1 time in total.
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

never-freakin-mind.....

If you notice throughout my post, it's RIDDLED with typos, well so was my code (which is rare for me)

"SELECT uname FROM account_info ORDER BY Name"

Should be

"SELECT uname FROM account_info ORDER BY uname"

In .net, IIS will point you in the general direction of your error, eg "line $, row (col) $, etc," or "Null reference exception" or "Object reference not set to the instance of an Object" etc.
Can this be set up in php, or will i have to continue using "Or Die(My_Error_Message_Here)"?

BTW, i run my own forums, and i know that i get mad if someone posts something that they didn't even try to find the soloution to theirself, or were just too lazy, but for some reason, after 14 hrs of trying different syntax's thinking that it was a script incompatability issue, i never noticed the typo. So, sorry for wasting forum space.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To get decent MySQL error messages you will need to use the or die() construct and mysqli_error(). Instead of:

Code: Select all

if ($result = mysqli_query($link, "SELECT uname FROM account_info ORDER BY Name")) {
   $row_cnt = mysqli_num_rows($result);
   printf("Result set has %d rows.\n", $row_cnt);
   mysqli_free_result($result);
}
try something like:

Code: Select all

$sql = "SELECT uname FROM account_info ORDER BY Name";

$result = mysqli_query($link, $sql) or die(mysqli_error().'<br />'.$sql);

echo 'Result set has '.mysqli_num_rows($result).' rows.';

mysqli_free_result($result);
Mac
User avatar
Alex-Grim
Forum Newbie
Posts: 17
Joined: Mon Dec 26, 2005 10:56 pm
Location: Hell's Gate

Post by Alex-Grim »

Hey, i was just reading the links in your signature and noticed that in one of your examples you use this:

Code: Select all

error_reporting(E_ALL);
does this mean that it will report all errors that are found?
if so, what is the proper way to impliment this, or does it "print / echo" the errors automatically(needing no additional code)?

thanks for your assistance with your previous post as well.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

that will make PHP output PHP errors, but a mysql error is different.. when you use mysql_query it sends the query to the mysql server, the mysql_query function returns false if mysql had an error and it is your responsibility to act on that error.. hence the or die(mysql_error()), the or part means if the previous function was false, die() stops the script and outputs its paramater and mysql_error() fetches the error from the last mysql query that went wrong.

so to php

Code: Select all

mysql_query('foobar this is a bad query');
is perfectly legal

Code: Select all

$result=mysql_query('foobar');
$variable = mysql_result($result,0,0);
is not because php expects the first paramater of mysql_result to be a mysql resultset, but in this case it is FALSE because the query from before failed, php will output an error "error $result is not a valid mysql result" or something to that effect (if php error reporting is turned on)

By the way your site is killing me, all CAPS, hard to read (small font / color scheme is awkward)
Post Reply