Jump to content

newbie Object DB Help


mad_php

Recommended Posts

My Object Oriented Php skills is limited. How can i connect to this database without having to instantiate a db connection on every class or function. Ie can i instantiate it on a global include file and run the $mysql->prepare statement without it crashing. Can anyone help me? Thanks

 

class menusController

  {

     

      function  Get ( $id )

      {

        **** > $mysqli = new mysqli("SERVER","USER","PASS","DB"); ****

       

        $stmt = $mysqli->prepare("call menusGet_proc(?)");

        $stmt->bind_param("i", $id);

     

        $stmt->execute();

       

        $stmt->bind_result($id,$name);

                 

        if ( $stmt->fetch() ){

            $clObject = new menusInfo ( $id, $name );

        }

       

        return $clObject;

      }

Link to comment
https://forums.phpfreaks.com/topic/48901-newbie-object-db-help/
Share on other sites

ok, no help?

 

let me try this again. I'm now using ADODB. The only way i can get the function in the class to work is this way. How can i moved the db open connection outside the class and still get it to work?

 

<?php

 

include $vpath . 'adodb/adodb.inc.php';

 

// menusController

class menusController

{

 

 

function  Get ( $id )

{

$server = "host";

$user = "user";

$pwd = "pass";

$db = "testdb";

 

$DB = NewADOConnection('mysql');

$DB->debug=true;

$DB->Connect($server, $user, $pwd, $db);

 

$rs = $DB->Execute("call insert_proc()");

 

 

}

            }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/48901-newbie-object-db-help/#findComment-239693
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.