Page 1 of 1
NewAdoConenction
Posted: Thu Jul 07, 2005 8:56 am
by NoFrills
I am trying to figure out of the connect to the databse I have, but everything I try isnt working.
I have gone thru dozens of examples, and read some forums, but still it doesn't work.
Code: Select all
<?
include ('adodb.inc.php'); //I place this file in the root directory /wwwroot
$db = NewADOConnection('ado_access'); //with this line included the page does not work?
...
...
Anbody know why it is not accepting the NewADOConnection line ?
I can connect to the DB with ASP, but I constructed the paged in PHP in a hope trying to learn the language.
Thanks
Posted: Thu Jul 07, 2005 9:32 am
by Chris Corbyn
I'm guessing that adodb.inc.php contains a class. In which case you instantiate it with new ADOConnnection().
Code: Select all
include ('adodb.inc.php'); //I place this file in the root directory /wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
If it's still giving errors after that post the contents of adodb.inc.php along with the code you're using it with and the errors you're getting

/wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
If it's still giving errors after that post the contents of adodb.inc.php along with the code you're using it with and the errors you're getting ;)case you instantiate it with new ADOConnnection().
Code: Select all
include ('adodb.inc.php'); //I place this file in the root directory /wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
If it's still giving errors after that post the contents of adodb.inc.php along with the code you're using it with and the errors you're getting

.php'); //I place this file in the root directory /wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
[/php:1:29039569ah case you instantiate it with new ADOConnnection().
Code: Select all
include ('adodb.inc.php'); //I place this file in the root directory /wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
If it's still giving errors after that post the contents of adodb.inc.php along with the code you're using it with and the errors you're getting

include ('adodb.inc.php'); //I place this file in the root directory /wwwroot
$db = New ADOConnection('ado_access'); //missing a space between New and class name
If it's still giving errors after that post the contents of adodb.inc.php along with the code you're using it with and the errors you're getting

Posted: Thu Jul 07, 2005 10:06 am
by NoFrills
Not to sound unreasonable, but the rest of the code I know works 100%, and has no relation to connection to a database. It is simply a few echo statements to place a table on the screen. Nothing to do with a database.
Looking at your code, I noticed that the New ADOconnection is in blue, indicating that it was recgonized by the program you used. Mine is blackened out indicating that it does no know what it is. I tried to seperate the NEW and ADoconenction, which goes against all the examples I seen. Still nothing.
I do not think it has to do with and code that is in the program, but the actual program recognizing that the NewADOConnection is a working command. I am not sure why it doesn't see that, or how to fix it. I thought maybe that the include was pointing to the wrong location, so I changed that line like a dozen times.
I do not get an error message per say, but when there is an error in the PHP code, the rest of the script doesn't not follow thru. So when I have the line with NewADOConnection included, I do not get any of my echo statements, when I have it // out, the codes works fine.
I just want to connect to a database I have on my website. I know how to do this in ASP, but not PHP. If you know of another way other than my problem, I would be grateful.
thx again
Posted: Thu Jul 07, 2005 10:31 am
by Chris Corbyn
Sounds like error reporting is either on very low or tunred off all together.
Add these lines to the very top of your PHP code.
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
E_ALL);
off all together.
Add these lines to the very top of your PHP code.
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set('display_errors', 1);
error_reporting(E_ALL);
Posted: Thu Jul 07, 2005 11:22 am
by NoFrills
You are a good man, did not know about that little simple code.
Warning: main(..\adodb.inc.php): failed to open stream: No such file or directory in e:\macromem.com\wwwroot\test7.php on line 31
Warning: main(): Failed opening '..\adodb.inc.php' for inclusion (include_path='.;c:\php4\pear') in e:\macromem.com\wwwroot\test7.php on line 31
Fatal error: Cannot instantiate non-existent class: adoconnection in e:\macromem.com\wwwroot\test7.php on line 34
Apparrently I do not know how to correct map to the include file. I have tried mutiple ways with ".." "/" and "\" and nothing seems to work.
all my files are located on wwwroot. So I thought I did not have to specify a location and could simple put include "Filename". That didn't work along with an assortment of other tries I made.
Thx for the help thus far.
Posted: Thu Jul 07, 2005 1:04 pm
by timvw
Asumming you have the following dir structure
Code: Select all
+c:/wwwroot/
- testscript.php
+ adodb/
- adodb.inc.php
Code: Select all
require_once('adodb/adodb.inc.php');
Posted: Thu Jul 07, 2005 2:51 pm
by NoFrills
getting an error message now:
Virtual Class -- cannot instantiate
Posted: Thu Jul 07, 2005 3:35 pm
by Chris Corbyn
Please post the code contained in ADOConnection.inc.php..... I think need to see exactly what it is so we know what you're trying to instantiate and we should be able to help you.
You're including a file then try to do something with it but we don't even know what's in the file

Posted: Thu Jul 07, 2005 4:36 pm
by NoFrills
The only thing I have in there is exactly what everybody has said to try.
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once('adodb/adodb.inc.php');
$db = New ADOConnection('ado_access');
That is it. Anything else is an echo statement.
Posted: Thu Jul 07, 2005 4:39 pm
by Chris Corbyn
The contents of this file ===== adodb.inc.php
i.e. The one you're inlcudeing in the script. It has all the data that's required to do what you're trying. Without it I/we can't see the problem here.
Posted: Thu Jul 07, 2005 5:21 pm
by NoFrills
OK gotcha. This program is some library download from the PHP.com website. I did not make it, but everywhere I go people are using it to connect their code to their database. So I gave it a try. I will post the contents below.
OK on second thought, it is a pretty large file to be posting on a forum. Would be enormous.
http://adodb.sourceforge.net/#download
So I am including the links to the download page.
Posted: Thu Jul 07, 2005 6:23 pm
by Chris Corbyn
Hmm.... ahhh... ohhh. Yeah you're right. I just downloaded it. It's over 3000 lines long.
But I do see that it's not a PHP error... it's an error written into the class. The constructor outputs it. looks like this isn't the correct way to handle the class. (see line 326 below)
Code: Select all
class ADOConnection {
//
// PUBLIC VARS
//
var $dataProvider = 'native';
var $databaseType = ''; /// RDBMS currently in use, eg. odbc, mysql, mssql
var $database = ''; /// Name of database to be used.
var $host = ''; /// The hostname of the database server
var $user = ''; /// The username which is used to connect to the database server.
var $password = ''; /// Password for the username. For security, we no longer store it.
var $debug = false; /// if set to true will output sql statements
var $maxblobsize = 262144; /// maximum size of blobs or large text fields (262144 = 256K)-- some db's die otherwise like foxpro
var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase
var $substr = 'substr'; /// substring operator
var $length = 'length'; /// string length ofperator
var $random = 'rand()'; /// random function
var $upperCase = 'upper'; /// uppercase function
var $fmtDate = "e;'Y-m-d'"e;; /// used by DBDate() as the default date format used by the database
var $fmtTimeStamp = "e;'Y-m-d, h:i:s A'"e;; /// used by DBTimeStamp as the default timestamp fmt.
var $true = '1'; /// string that represents TRUE for a database
var $false = '0'; /// string that represents FALSE for a database
var $replaceQuote = "e;\\'"e;; /// string to use to replace quotes
var $nameQuote = '"e;'; /// string to use to quote identifiers and names
var $charSet=false; /// character set to use - only for interbase, postgres and oci8
var $metaDatabasesSQL = '';
var $metaTablesSQL = '';
var $uniqueOrderBy = false; /// All order by columns have to be unique
var $emptyDate = '&nbsp;';
var $emptyTimeStamp = '&nbsp;';
var $lastInsID = false;
//--
var $hasInsertID = false; /// supports autoincrement ID?
var $hasAffectedRows = false; /// supports affected rows for update/delete?
var $hasTop = false; /// support mssql/access SELECT TOP 10 * FROM TABLE
var $hasLimit = false; /// support pgsql/mysql SELECT * FROM TABLE LIMIT 10
var $readOnly = false; /// this is a readonly database - used by phpLens
var $hasMoveFirst = false; /// has ability to run MoveFirst(), scrolling backwards
var $hasGenID = false; /// can generate sequences using GenID();
var $hasTransactions = true; /// has transactions
//--
var $genID = 0; /// sequence id used by GenID();
var $raiseErrorFn = false; /// error function to call
var $isoDates = false; /// accepts dates in ISO format
var $cacheSecs = 3600; /// cache for 1 hour
var $sysDate = false; /// name of function that returns the current date
var $sysTimeStamp = false; /// name of function that returns the current timestamp
var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets
var $noNullStrings = false; /// oracle specific stuff - if true ensures that '' is converted to ' '
var $numCacheHits = 0;
var $numCacheMisses = 0;
var $pageExecuteCountRows = true;
var $uniqueSort = false; /// indicates that all fields in order by must be unique
var $leftOuter = false; /// operator to use for left outer join in WHERE clause
var $rightOuter = false; /// operator to use for right outer join in WHERE clause
var $ansiOuter = false; /// whether ansi outer join syntax supported
var $autoRollback = false; // autoRollback on PConnect().
var $poorAffectedRows = false; // affectedRows not working or unreliable
var $fnExecute = false;
var $fnCacheExecute = false;
var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char
var $rsPrefix = "e;ADORecordSet_"e;;
var $autoCommit = true; /// do not modify this yourself - actually private
var $transOff = 0; /// temporarily disable transactions
var $transCnt = 0; /// count of nested transactions
var $fetchMode=false;
//
// PRIVATE VARS
//
var $_oldRaiseFn = false;
var $_transOK = null;
var $_connectionID = false; /// The returned link identifier whenever a successful database connection is made.
var $_errorMsg = false; /// A variable which was used to keep the returned last error message. The value will
/// then returned by the errorMsg() function
var $_errorCode = false; /// Last error code, not guaranteed to be used - only by oci8
var $_queryID = false; /// This variable keeps the last created result link identifier
var $_isPersistentConnection = false; /// A boolean variable to state whether its a persistent connection or normal connection. */
var $_bindInputArray = false; /// set to true if ADOConnection.Execute() permits binding of array parameters.
var $_evalAll = false;
var $_affected = false;
var $_logsql = false;
/**
* Constructor
*/
function ADOConnection()
{
die('Virtual Class -- cannot instantiate');
}
//and it goes on for 3000 lines..............
You don't need to instantiate this... you simply need to include it and use it. I'd suggest looking at some of the examples in the /test directory.
adodb documentation wrote:
Installation
Make sure you are running PHP4.0.4 or later. Unpack all the files into a directory accessible by your webserver.
To test, try modifying some of the tutorial examples. Make sure you customize the connection settings correctly. You can debug using:
<?php
include('adodb/adodb.inc.php');
$db = ADONewConnection($driver); # eg. 'mysql' or 'oci8'
$db->debug = true;
$db->Connect($server, $user, $password, $database);
$rs = $db->Execute('select * from some_small_table');
print "<pre>";
print_r($rs->GetRows());
print "</pre>";
?>
ADONewConnection(), not NewADOConnection()....
Posted: Thu Jul 07, 2005 6:30 pm
by timvw
method NewADOConnection (not the constructor)
I ran the following code on localhost... Works just fine...
Code: Select all
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
require_once('generic/ext/adodb/adodb.inc.php');
$db =& NewADOConnection('ado_access');
if (!$db) echo "Could not make connection";
?>
Posted: Thu Jul 07, 2005 6:35 pm
by NoFrills
Strangely that is what I did intially, I was using ADONewConnection() with no luck. But at that time, I belive I had the wrong include statement and that was prevention anything from working. But by the time I was told of the error, I already had changed the ADONewConnection() to another example I had seen.
I really appreciate the time you gave to this. I did include the original ADONewConnection() and the page does load up like its suppose too. Now I can finally continue with saving and retrieving data to the database. Hopefully that will go smoother than connecting.
Thank you again.
** If I might ask, what is the difference between the Include and require_once statement?
Posted: Thu Jul 07, 2005 6:46 pm
by timvw