Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Equivalent

Status
Not open for further replies.

RENO9

Technical User
Dec 8, 2005
27
GB
I currently use the following bit of code to validate a user login which works fine in MySQL but to no avail in Oracle, could anyone tell me what the equilivent in oracle is of the line,
if ($qry->numRows() == 0)
Code:
	if ($qry->numRows() == 0)	//WORKS in MySQL
	{
	 echo "Logon Failure\n";
	 $_SERVER['PHP_AUTH_USER'] = "UNAUTHORISED";
 	 exit;
	}
Thanks
 
Reno,

To ensure that we give you the correct advice, could you please translate your working MySQL code into non-syntax-based generic pseudo code?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Ok i will give it a shot,

The SQL statement queries the username and password in the database
if it can not find a match in any row (the number of rows = 0) and throws up an error {Script shown above works fine in MySQL}
if it is correct, the number of rows = 1 and contiunes processing


Cheers
 
Sorry, Reno, for not asking this in my original followup...One additional question: For what "coding environment" do you want the code...SQL, PL/SQL, or other? (...because your original syntax is not suitable for Oracle's SQL or PL/SQL environments, regardless.)

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
Im not to familiar with Oracle but i think the answer to what your asking is SQL*Plus...
 
Again, apologies for not expressing all of my clarification questions up front, but when you say, "The SQL statement queries the username and password in the database...", where, specifically, in the database are you looking for username and password?...If it is the Oracle username and password, then Oracle validates all of that before connection to Oracle can occur. If you are storing an application username and password in your own application-security table, then could you please list your actual (intended) application-security tablename and username and password column names? At that point, I can assert some SQL code that works in SQL*Plus. (Sorry for the run-around...I just want the solution to work first time for you.[smile])

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[ Providing low-cost remote Database Admin services]
Click here to join Utah Oracle Users Group on Tek-Tips if you use Oracle in Utah USA.
 
No Problem, the table is customer with columns customerID and (clear-text) password, i.e.
Code:
$sql = "SELECT * FROM customer WHERE customerID = '{$_SERVER['PHP_AUTH_USER']}' AND password = '{$_SERVER['PHP_AUTH_PW']}'";
Thanks
 
This is neither Oracle, nor mySQL, this is php code, thus Oracle equivalent of the code you sent should be exactly the same :)

What kind of "no avail" do you mean? Errors? Could you send $sql value that fails?

Regards, Dima
 
I think that the original question was: What is the equivalent for an Oracle connection of the method NumRows() of the MySQL query object? Perhaps the PHP forum might be a better place to look. From a brief look at the functions reference ( it looks as though you need ora_numrows() on an open cursor.
 
Hi sem,

It does not seem to fail it just seems to bypass the code, the line above has error checking with regards to the sql statement i.e.
Code:
	$qry = $db->query($sql); // Execute the query.
	if (DB::iserror($qry)) {
	  die($qry->getMessage());
    }
but after that it just bybasses the statement
Code:
if ($qry->numRows() == 0)

Cheers
 
How could i get around it? i have tried to use
Code:
elseif ($qry->numRows() == -1)
but to no avail...
 
Does it equal to -1?

Isn't it easier to check what the real $qry->numRows() value equals to instead of (countless) postings about what it doesn't? In any case your problem has nothjing to do with Oracle and IMHO should be answered by php guys, because the issue is not in what Oracle returns but rather in what and how it's asked about.

Regards, Dima
 
Sorry for the numerous postings but im tearing my hair out and i cant figure out why its not working, the output to the query $qry->numRows() in,
MySQL = 1 (Which is what i expect)
Oracle it returns Object id #6 (?)

Thanks
 
Again: Object id #6 is not returned by Oracle but rather by php library (PEAR DB?) that works with Oracle. Its developers only know what they ask Oracle about, what Oracle answers and how that answer is exposed to other php users. This is not an Oracle issue, this is an issue of php library. In general Oracle doesn't know the number of rows returned before returning them.

But if your only task is to check whether the query retreives anything or not then you may fetch the first row, this is far more clean, efficient and portable solution.

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top