Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/253831-pdo/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301344
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301347
Share on other sites

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 

Link to comment
https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301352
Share on other sites

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);

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/253831-pdo/#findComment-1301376
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.