hackalive Posted December 26, 2011 Share Posted December 26, 2011 Firstly hoping everyone had a good Christmas, Next, I am trying to use this code https://github.com/geoloqi/oauth2-php And using the PDO I setup the tables etc but cannot link it to my db. In my browser i go http://localhost/server/examples/pdo/addclient.php I need to get it to link to a db but cant. Any help is much appreciated. Cheers in advance. Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2011 Share Posted December 26, 2011 What exactly symptom or error did you see in front of you that leads you to believe that the script has a problem connecting to your database and what steps have you taken to troubleshoot the problem? Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301343 Share on other sites More sharing options...
hackalive Posted December 26, 2011 Author Share Posted December 26, 2011 Basically i opened all of the files in Notepad ++ and could not find anywhere to add my db details! I found this line: * new PDOOAuth2( new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass') ); in the file: OAuth2StoragePdo.php But as you can see it is commented out and is surrounded by the following lines: /** * @file * Sample OAuth2 Library PDO DB Implementation. * * Simply pass in a configured PDO class, eg: * new PDOOAuth2( new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass') ); */ There are no instructions on how to add the DB details and/where. If I un-comment the above line in its exact location and put in my details I get this error: Fatal error: Class 'PDOOAuth2' not found in webroot\server\examples\pdo\lib\OAuth2StoragePdo.php on line 11 So any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301344 Share on other sites More sharing options...
kicken Posted December 26, 2011 Share Posted December 26, 2011 Basically i opened all of the files in Notepad ++ and could not find anywhere to add my db details! That is because there is no place to put your details. That class does not connect to the database on it's own. You do that in your code, then pass the handle to the classes' constructor. Read that comment you pointed out. It tells you to do just that, and even shows you exactly how to do it. /** * @file * Sample OAuth2 Library PDO DB Implementation. * * Simply pass in a configured PDO class, eg: * new PDOOAuth2( new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass') ); */ Perhaps you will understand better if it is separated out: $dbConnection = new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass'); $oauth = new PDOOAuth2($dbConnection); Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301347 Share on other sites More sharing options...
hackalive Posted December 26, 2011 Author Share Posted December 26, 2011 @kicken Thanks for the advice, but can you suggest where i add those lines? Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301348 Share on other sites More sharing options...
hackalive Posted December 26, 2011 Author Share Posted December 26, 2011 Adding $dbConnection = new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass'); $oauth = new PDOOAuth2($dbConnection); To line #11 on that file still returns the same error message! Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301351 Share on other sites More sharing options...
hackalive Posted December 26, 2011 Author Share Posted December 26, 2011 I added define("PDO_DSN", "mysql:dbname=dbname;host=localhost"); define("PDO_USER", "user"); define("PDO_PASS", "pwd"); which got rid of the above error, now i get this error Catchable fatal error: Argument 1 passed to OAuth2StoragePDO::__construct() must be an instance of PDO, none given, called in webroot\server\examples\pdo\addclient.php on line 13 and defined in webroot\server\examples\pdo\lib\OAuth2StoragePdo.php on line 50 Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301352 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2011 Share Posted December 26, 2011 The comment/documentation in that class definition has the wrong class name and even the include statement in the addclient.php code is for the wrong file. In addclient.php, you would change the $oauth = new OAuth2StoragePDO(); statement so that the (missing) parameter contains an instance of your desired PDO class. Assuming that your page makes an instance of a PDO class at some point - $dbConnection = new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass'); Change any use of new OAuth2StoragePDO() in the 'example' pages to - new OAuth2StoragePDO($dbConnection) Line 15 of addclient.php would become - $oauth = new OAuth2StoragePDO($dbConnection); Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301376 Share on other sites More sharing options...
hackalive Posted December 26, 2011 Author Share Posted December 26, 2011 so on ever .php page in 'example' add $dbConnection = new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass'); and Change any use of new OAuth2StoragePDO() in the 'example' pages to - new OAuth2StoragePDO($dbConnection) ? Quote Link to comment https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.