| View previous topic :: View next topic |
| Author |
Message |
danny876
Joined: 31 Aug 2006 Posts: 5
|
Posted: Mon Oct 02, 2006 1:56 pm Post subject: Authentication using MDB2 |
|
|
Hello all.
My problem is quite simple but I have been stuck on it for about 2 months now. I must be really dumb! So please help if you can!!
Task: To create a basic log in form using the Auth package. Example taken from the Auth package documentation.
Success = Using the DB container
Failure = Using the MDB2 container
Here's what I have observed:
1) It returns an error when trying to do quote('username', 'type').
2) Printing the error says that it cannot find package MDB2/Datatype.php
I am a bit confused as to why it is looking for a file called datatype.php
as it's not included in the Auth or MDB2 download.
It's exactly the same set up for DB (which works like a dream).
I have placed the mysql.php in the folders but I am not sure what else I need to do.
PLEASE HELP I NEED TO DO THIS TO MOVE ON - can't use DB coz it's slow and out of date. Besides - i dislike unsolved problems.
THANK YOU!!
Dan. |
|
| Back to top |
|
 |
primeminister Site Admin

Joined: 16 Apr 2006 Posts: 92 Location: Netherlands
|
Posted: Tue Oct 03, 2006 8:28 am Post subject: |
|
|
Hi Dan,
Can you give me the way you connect to MDB2?
This is what they say on the PEAR Website in the MDB2 End-user documentation:
| Code: |
<?php
require_once 'MDB2.php';
$dsn = array(
'phptype' => 'mysql',
'username' => 'someuser',
'password' => 'apasswd',
'hostspec' => 'localhost',
'database' => 'thedb',
);
// don't really know if this is
$options = array(
'debug' => 0,
'portability' => MDB2_PORTABILITY_ALL,
);
// uses MDB2::factory() to create the instance
// and also attempts to connect to the host
$mdb2 =& MDB2::connect($dsn, $options);
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
?>
|
I think you don't give the phptype or quote() is messingup your DSN |
|
| Back to top |
|
 |
danny876
Joined: 31 Aug 2006 Posts: 5
|
Posted: Tue Oct 03, 2006 12:36 pm Post subject: Hi again |
|
|
THANK FOR THE REPLY!
Here you go:
This code I think is very similar to the example given in the Auth documentation.
I really realy appreciate the help!
Dan.
| Code: |
<?php
require_once "../../pear/auth/Auth.php";
function loginFunction()
{
/*
* Change the HTML output so that it fits to your
* application.
*/
echo "<form method=\"post\" action=\"index.php?login=1\">";
echo "<input type=\"text\" name=\"username\">";
echo "<input type=\"password\" name=\"password\">";
echo "<input type=\"submit\">";
echo "</form>";
}
if (isset($_GET['login']) && $_GET['login'] == 1) {
$optional = true;
} else {
$optional = false;
}
$options = array(
'dsn' => 'mysql://user:password@host/database',
);
$a = new Auth("MDB2", $options, "loginFunction");
$a->start();
echo "Everybody can see this text!<br />";
if (!isset($_GET['login'])) {
echo "<a href=\"index.php?login=1\">Click here to log in</a>\n";
}
if ($a->getAuth()) {
echo "YOU ARE LOGGED IN!";
} else {
echo 'I am not logged in';
echo '<br>'.$_GET['login'];
}
?>
|
|
|
| Back to top |
|
 |
danny876
Joined: 31 Aug 2006 Posts: 5
|
Posted: Tue Oct 03, 2006 12:37 pm Post subject: Also |
|
|
| Also I am using the MDB2 container found in Auth. |
|
| Back to top |
|
 |
danny876
Joined: 31 Aug 2006 Posts: 5
|
Posted: Tue Oct 03, 2006 11:07 pm Post subject: More info... |
|
|
Just to clarify that is goes wrong at this point....
The key thing to note here, is that it goes wrong before it executes this query.
So... what could I be doing wrong that would prevent quote() from working correctly?? A small portion of the error I receive (which I should have placed at the start) is...
| Quote: |
MDB2_Error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => -4 [message] => MDB2 Error: not found [userinfo] => unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php'
|
Here is the segment where the code goes ... wrong.
[code]
$query = sprintf("SELECT %s FROM %s WHERE %s = %s",
$sql_from,
$this->options['final_table'],
$this->options['final_usernamecol'],
$this->db->quote($username, 'text')
);
[/code]
It manages to pass the username as i have done the below which prints the username (before $query).
echo $username; exit();
Thanks to those brainy enough to help
Dan. |
|
| Back to top |
|
 |
danny876
Joined: 31 Aug 2006 Posts: 5
|
Posted: Fri Oct 06, 2006 9:45 pm Post subject: SOLVED |
|
|
Right...Basically here is what I did to fix this.
Deleted everything and started again. I must have done a manual installation on a shared host/server incorrectly.
Rule No. 1 : Do not change any of the includes with pear, auth, mdb2 or db.
Rule No. 2 : Do not enter a DSN and you'll be passing this through from a secure location anyhow.
Rule No. 3 : For manual installations on shared host this is the structure
-- A Folder you call MyPearFolder
---- Pear
---- MDB2
---- DB
---- Auth
------Auth
Rule No. 4 : Never ever give up!
Rule No. 5 : Use the examples supplied on the pear website - they simple and are invaluable.
Rule No. 6 : Set your include path to be the location of host/MyPearFolder/
Rule No. 7 : If unsure on how to connect using your specific database container. Look at the tests include in the Auth folder, they will include example $options (=connection parameters). Usually easy as CPE jobs (copy, paste and edit jobs) don't u just love acronyms.
At the top of every script place the following:
| Code: |
ini_set("include_path", "/host/belowrootordomain/MyPearFolder/");
|
I truely hopes this helps others who a little pear-like challenged..
Been stuck now for so long i haven't got anything in my head to continue with LOL!
I'll be creating a blog with this info in soon,
hope people will find it of interest!
Kind Regards,
A now very happy chappy.
Dan. |
|
| Back to top |
|
 |
primeminister Site Admin

Joined: 16 Apr 2006 Posts: 92 Location: Netherlands
|
Posted: Sun Oct 08, 2006 2:57 pm Post subject: |
|
|
He Dan,
Great that you've got that working and thanx for sharing.
cya! |
|
| Back to top |
|
 |
mrsocks
Joined: 03 Feb 2007 Posts: 14
|
Posted: Sun Feb 04, 2007 8:45 am Post subject: |
|
|
did you ever really figure out what was going on with this issue?
i am trying to use insert with mdb2 and the insert is throwing the:
'unable to find package 'MDB2_Datatype' file 'MDB2/Datatype.php''
error.
any suggestions as to what really caused this?
thanks. |
|
| Back to top |
|
 |
|