DatabaseStandard-Talk
OK, I've posted version 0.1 of adodb-connect.php to the Database Standard page. It works with my developmental version of DataQuery (not yet public), using mysql. I haven't tested other database types. The script does nothing by itself ... you will need to write a script to call the ADOdbConnect function and display the result.
I'm particularly curious whether the global variables make sense. We already agreed on $Databases for the configuration details. I've taken the liberty of using $ADOdbLocation for the location of the adodb folder and $DB['database_name'] for the database object, but I'm open to better suggestions.
Ben Stallings November 01, 2006, at 01:03 PM
- I'm getting whiplash considering all these different options... I thought we had agreed to go with ADOdb! Do we have to reopen the discussion now to consider using ADOdb-lite instead? Or are they similar enough that we can just write a different connection module later and let recipes use the same functions?
I'm not trying to give anyone whiplash. Someone on-list was saying ADOdb-lite was so much lighter, and was only missing a few heavyweight functions. I'm fine with just plain old ADOdb -- and if people need to strip out databases they're not using, they can do that.
Thanks for uploading a script. I'll look when I get a chance.
XES November 01, 2006, at 01:14 PM
Hello,
Is anyone else having problems with the ADODB-connect script? My error occurs, I believe on line 97, where the mysql connect info is called. I'm in an airport right now, but will post the exact problem when I have more time.
Thanks,
Gamma November 14, 2006, at 09:00 PM AST
I was able to use the script.
I would double-check the order in which you're including information & recipes in config.php. Sometimes the order doesn't matter much, sometimes it does. I don't think it matters much in this case (I do need to include the adodb-connect.php script BEFORE including the scripts using it, and make sure the variables needed are definef first), but in terms of putting recipes in config.php, usually you define the variables needed by a script before including it:
$Databases['users'] = array( 'driver' => 'mysql', 'hostname' => 'localhost', 'database' => 'srago_similepedia', 'username' => 'root', 'password' => 'mypassword'); include_once "cookbook/adodb-connect.php";
The includes for any scripts USING adodb-connect.php would be in config.php under that.
(Yes, I shouldn't use the mysql root to connect to the database -- this database is a testing database on my laptop, not a public server.)
If you can't connect, double check that you have defined the $Databases array and values appropriately. In my recipe, I would have to have the commands:
include_once "$FarmD/cookbook/adodb-connect.php"; ADOdbConnect('users');
And "users", as you can see from me setting the array $Databases, must be the index of the array explicitly named "$Databases" holding the database connection information.
Let me know if that doesn't help.
XES November 15, 2006, at 06:05 AM
Hello, XES and thank you for the prompt response.
Here is the response when I attempt to login to my protected page:
Missing file: /home/gammaray/public_html/cookbook/adodb/drivers/adodb-://.inc.php
ADONewConnection: Unable to load database driver ''
Fatal error: Call to a member function on a non-object in /home/gammaray/public_html/cookbook/adodb-connect.php on line 101
I had checked and my inclusion is in the same order you stated. Now, these inclusions are also before the inclusion of the following:
include_once("cookbook/AuthUserDbase-2.0.0.php");
include_once('scripts/authuser.php');
It might be important to note that My PmWiki version is the 2.1.26, I have not upgraded to any of the beta versions yet. I have created the table to contain the login accounts, but the fields are still empty.
I appreciate your help!
Gamma November 16, 2006, at 09:50 AM CST
Hi, Gamma,
You need to download and install the open-source PHP package ADOdb and make sure the adodb folder is placed inside your cookbook folder.
It looks like either you don't have it installed, or it's in another location.
If it's in another location, you can change the setting in config.php by telling the program exactly where it is kept:
$ADOdbLocation = '/www/adodb/adodb.inc.php';
Crisses
Hello, Crisses,
I did have adodb installed in the cookbook directory already. Just to try a change and see what would happen, I changed "mysql" to "mssql" and then to "access" in the driver definition, and I get a blank page, but no error.
This line in adodb-connect.php is what is giving me trouble I believe. Is it possible I have downloaded one that is incorrect?
// standard DSN connection $dsn = $Databases[$dbName]['driver'].'://' . ($Databases[$dbName]['username'] ? $Databases[$dbName]['username'].':' . $Databases[$dbName]['password'].'@' : '') . ($Databases[$dbName]['hostname'] ? $Databases[$dbName]['hostname'].'/' : '') . $Databases[$dbName]['database'];
Thanks,
Gamma
Hi, Gamma,
Check this-- you need to have the driver in the adodb folder like this:
cookbook/adodb/drivers/adodb-mysql.inc.php
If you are missing that file, you need to either re-install, or install the database drivers. Did you install the adodb full package from http://adodb.sourceforge.net/#download under "PHP Download"? If you uploaded the package to your server, it's possible that you didn't finish the entire transfer?
Crisses
Hello, Crisses,
I checked and everything was there. I then downloaded it again (newer version, 4.93a) and FTP'ed it to the cookbook directory. I'm still having the same error.
I still believe the problem lies in the lines of code in ADODB-connect.php I included above.
To experiment, I changed the lines in the file (line no. 95 in my file) from:
// standard DSN connection $dsn = $Databases[$dbName]['driver'].'://'
to:
// standard DSN connection $dsn = $Databases[$dbName]['driver'].':'
(removing the slashes)
and I got:
Missing file: /home/gammaray/public_html/cookbook/adodb/drivers/adodb- mysql:gammaray_gamma:greath0use@localhost/gammaray_alumni.inc.php ADONewConnection: Unable to load database driver '' Fatal error: Call to a member function on a non-object in /home/gammaray/public_html/cookbook/adodb-connect.php on line 101
The first line has all my DB login information appended to the driver, but the driver file name is split at the beginning and end.
I'm no PHP codewriter, but is it possible to modify those lines so the mysql driver is called all the time and no other choices possible?
Thanks,
Gamma
Hi, Gamma:
To do that:
// standard DSN connection $dsn = 'mysql://'
Those slashes ARE needed -- it's not an error in the program.
If it doesn't work after you write in mysql, something else is going on. I might want you to send me your entire config.php (just change the passwords in it to something like "peppermint" :) ).
Crisses
Hello, Crisses and thank you for your time in figuring this out.
I changes the line as you suggested and received the following:
Warning: parse_url(mysql://) [function.parse-url]: Unable to parse url in /home/gammaray/public_html/cookbook/adodb/adodb.inc.php on line 4006 Fatal error: Call to a member function on a non-object in /home/gammaray/public_html/cookbook/adodb-connect.php on line 102
which shows that the driver file is actually there, but maybe the problem lies somewhere else.
here is my file as you requested:
Thanks,
Gamma
I see this error:
$AUDBaseTable['database'] = 'users';
should be:
$AUDBaseTable['database'] = 'activealumni';
At that point your parsing error should be fixed. I would revert your adodb-connect.php back to :
// standard DSN connection $dsn = $Databases[$dbName]['driver'].'://'
The following can be omitted from config.php since you seem to be using all the default settings:
// which fields in the table contain the following data? $AUDBaseTable['user_field'] = 'username'; $AUDBaseTable['pw_field'] = 'password'; // which password encryption scheme to use // normally "md5" or "sha1". // May also be admin-defined function; use the name of the function, // and define the function in config.php $AUDBaseTable['encrypt_f'] = 'md5'; // which field contains the following data? $AUDBaseTable['email'] = 'email'; $AUDBaseTable['validate_code'] = 'validatecode'; $AUDBaseTable['validate_field'] = 'validatefield'; $AUDBaseTable['date_joined'] = 'signupdate'; // not used at the moment - may use ADOdb's internal //international error code feature $AUDBaseTable['lang'] = 'en';
Make sure to leave in:
// these settings are required for stand-alone use only (defaults listed) $AUDBaseTable['standalone'] = true; // set to true for stand-alone use
Let me know if that helps.
XES November 17, 2006, at 09:25 AM
Who-Hoo!
It sure works now! Thank you very much for finding the error!
Such a small mistake on my part.
This is such brilliant coding by you and Mr. Stallings! I added the sign-up form and appreciate how it shows only the appropriate form depending on what is needed in the signup/validate process.
Thanks again!
Gamma
You're welcome :)
XES November 17, 2006, at 02:36 PM
Yesterday I tried connecting two simultaneous MySQL databases using this recipe, and (long story short) I found that ADOdb is a little bit too frugal with its resources... if you connect to a second database with the same login information as a first, it reuses the connection_id (internally) so that the first database is no longer accessible.
For example, if you have the same username and password specified in the $Databases variable for connections One and Two, and your recipe says,
ADOdbConnect('One'); ADOdbConnect('Two'); print_r($DB['One']->MetaTables());
you'll get a list of the tables in database Two!
Needless to say this is frustrating, but the solution for now is to use a different login and password for each database.
If anyone has a better solution, I'd love to hear it!
Ben Stallings January 08, 2007, at 03:12 PM
Could someone provide installation instructions for this? Each time I try to activate ADOdb/adodb_connect, I get MySQL errors saying that the username is an invalid hostname (!?). They are wrongly defined somewhere.
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL Server Host 'my_db_username' (1) in /home/WWW/pmwiki/cookbook/adodb/drivers/adodb-mysql.inc.php on line 365 Fatal error: Call to a member function on a non-object in /home/WWW/pmwiki/cookbook/adodb-connect.php on line 94
I'm using adodb498.zip, the latest selectquery and have it all in the right locations, as far as I know. This is in my local/config.php :
$Databases['tralala'] = array( 'driver' => 'mysql', 'hostname' => 'dbhost.nl', 'database' => 'hallo', 'username' => 'my_db_username', 'password' => 'something'); include_once "$FarmD/cookbook/adodb-connect.php"; ADOdbConnect('tralala'); $SelectQuerySettings['database'] = 'tralala';
So, what is going wrong where?
~Someone
Ben,
That is a documented bug about ADOdb. I can't seem to find it at the moment but remember reading it somewhere.
Guy Moreau April 18, 2008, at 20:58 EST
So what exactly needs to go where? (It does not say this in the instructions..) Do I need to put the "include_once" somewhere or does putting it in the cookbook folder imply it is included? Where do I put the connection link (I have that outside of those files, I have setup a more secure place for the database password)?
Also, for UpdateForm I had to make a connection from config.php, so how do I use them both at once?
~Someone
You do not need to put the "include_once" line in your config.php unless the recipe you are installing specifically says that you need to. However, the nature of "include_once" is that it will not hurt anything to call it multiple times.
However, if you are using the ADOdbConnect() function in your config.php, remove it. That function is designed to be called only from a recipe file, not from config.php. I have made the instructions clearer on that point. Sorry about the confusion!
Ben Stallings April 20, 2008, at 11:56 AM
For the case of SelectQuery, all you need to do is define the database as per the DatabaseStandard and set a variable telling SelectQuery which connection to use. SelectQuery does the rest, including the ADOdb requirements and connection.
If you want the password safe, that's fine. You just need the right PHP code to fetch and include the password in the correct variable. Leave the rest for the recipes. It seems you are trying too hard to get this to work. Here is what it should look like for SelectQuery:
$Databases['tralala'] = array( 'driver' => 'mysql', 'hostname' => 'dbhost.nl', 'database' => 'hallo', 'username' => 'my_db_username', 'password' => 'something'); $SelectQuerySettings['database'] = 'tralala';
Guy Moreau April 21, 2008, at 8:37 EST
Hello, I am trying to connect to an oracle database using oci8 driver. I used adodb-connect.php without any change and got the following error message:
Missing file: /opt/app/dmu/htdocs/dmu_TEST/cookbook/adodb/drivers/adodb-://.inc.php
Fatal error: Call to a member function ErrorMsg() on a non-object in /opt/app/dmu/htdocs/dmu_TEST/cookbook/adodb-connect.php on line 105
I then tried to do the following
- $dsn = $Databases[$dbName]['driver'].'://'
- . ($Databases[$dbName]['username'] ? $Databases[$dbName]['username'].':'
- . $Databases[$dbName]['password'].'@' : '')
- . ($Databases[$dbName]['hostname'] ? $Databases[$dbName]['hostname'].'/' : '')
- . $Databases[$dbName]['database'];
$dsn = 'oci8://'; $DB[$dbName] = ADONewConnection($dsn);
the error message resulting was:
Fatal error: Call to a member function ErrorMsg() on a non-object in /opt/app/dmu/htdocs/dmu_TEST/cookbook/adodb-connect.php on line 105
any suggestion?To
Chris, Thursday 30 April at 13:00 (GMT+1)
To Chris, a few years late: I have run into a similar problem. But I am using mysql or mysqli. If ADO is not able to connect, it does not seem to fill in the object enough to give an error message. I will post to the list. A workaround to the ErrorMsg Fatal error is to replace the call to ErrorMsg with your own message. It will probably not be very informative (unable to connect or something) but at least it will not be fatal.
Talk page for the DatabaseStandard recipe (users).