mad_php Posted April 27, 2007 Share Posted April 27, 2007 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 More sharing options...
mad_php Posted April 27, 2007 Author Share Posted April 27, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.