NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[resolved] Code completion issue with PEAR/MDB2


Joined: 08 Sep 2007
Posts: 5
Reply with quote
Project setting has "C:\wamp\php\PEAR\pear" in the "Code insight includes" section.

code is:

Code:


require_once ("MDB2.php");

$dsn = array(
      'phptype'  => 'mysqli',
      'username' => 'root',
      'password' => '',
      'hostspec' => 'localhost',
      'database' => 'site',
      );
      
$options = array(
      'debug' => 2,
      /*'result_buffering' => false,*/
      );

// create MDB2 instance
MDB2::factory();
if (PEAR::isError($mdb2)) {
   die($mdb2->getMessage());
}

$table = 'users';
$query = "INSERT INTO $table (U_UserName, U_Password, U_FirstName, U_LastName) VALUES (:name, :pass, :firstName, :lastName)";
$stmt = $mdb2->prepare($query, array('name' => 'text', 'pass' => 'text', 'firstName' => 'text', 'lastName)' => 'text'), true);
$stmt->execute(array('name' => 'test1', 'pass' => 'polar', 'firstName' => 't1', 'lastName' => 't2'));



the $mdb2->prepare() and $stmt->execute() don't get AutoComplete/Tooltip. The errors are:





How do I get it to work properly?

Thanks
View user's profileFind all posts by devboySend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
btw, seems you forgot to assign $mdb2 variable with value returned from MDB2::factory();
but anyway, phpdoc for MDB2 is a bit broken and is not useful for PhpED's code completion engine. Indeed, MDB2::factory()'s phpdoc for returning value is:
Code:
     * @return  mixed   a newly created MDB2 object, or false on error

So it tells that the class name is "a", so it can't be found Smile

if you change it to
Code:
     * @return  mixed  MDB2_Driver_Common a newly created MDB2 object, or false on error

it will start working for you.

The same goes for MDB2_Driver_Common::prepare where you may want to add MDB2_Statement_Common as a returning class type:


_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 14 Jun 2007
Posts: 67
Reply with quote
would an easier way be:
Code:
/** @var mdb2 MDB2_Driver_Common */
$mdb2 = MDB2::Factory();
View user's profileFind all posts by CjungeSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
or even shorter
Code:
/** @var MDB2_Driver_Common */
$mdb2 = MDB2::Factory();

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Sep 2007
Posts: 9
Reply with quote
I got the same problem.
If I new the MDB2 class,the code completion is fine.
But If I use MDB2::connect,it will fail.
The $dsn-> can't show the code completion.



And sometimes,$dsn2-> will NOT appear code completion....why?
View user's profileFind all posts by timeriverSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
It's all explained in this thread. There are no problems on the IDE side.
Please read my post above.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Sep 2007
Posts: 9
Reply with quote
I had tried many times,but still failed.Sad
I already set the code insight path,and I extract the PEAR class into phped/include_lib.

php.ini's include path:
include_path = ".;C:\Program Files\nusphere\phped\include_lib;C:\Program Files\nusphere\phped\include_lib\PEAR"


↑It's just no MDB2,but have smarty:shock:



Can you help me to figure out what's wrong with it?
Thanks a lot!
View user's profileFind all posts by timeriverSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Setting include_path will not change anything in code completion functionality. It's a pure php setting and may affect how and what php includes. It can't and won't be used by the ide to find out where the project files are. You have to create project, if you still havn't done it and set its properties, including Code Insight Includes list where you need path to PEAR.
Then don't forget about changes to PEAR's phpdoc blocks I told about above.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Sep 2007
Posts: 9
Reply with quote
Thanks a lot!
After I add the MDB2_Driver_Common in the phpdoc comment,the code completion is ok.
But it just can't appear all funcitons:


It should appear fetchOne,fetchAll...etc,but it's not.
Which comment should I add to?
View user's profileFind all posts by timeriverSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Quote:
It should appear fetchOne,fetchAll...etc,but it's not.

Not at all. If you check MDB2_Driver_Common sources, you'll find that there are no such methods in it. They are available with MDB2_Result_Common class.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 21 Sep 2007
Posts: 9
Reply with quote
Sorry,I can't clearly know why the compiler can pass,but I will check it out.
Thank you.
View user's profileFind all posts by timeriverSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
"compiler" has no relation. Php resolves references to methods at run-time. So you won't see such errors until you run your code.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
[resolved] Code completion issue with PEAR/MDB2
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic