php - mysqli_prepare() expects parameter 1 to be mysqli, object given -
alright. basically. here's code.
login.php
require_once("./libs/db_cxn.php"); $cxn = new newconnection(); $stmt = "select users.username users username=$username , password=md5($password)"; $qry = \mysqli_prepare($cxn, $stmt); $res = mysqli_execute($qry);
db_cxn.php
class newconnection{ function __construct(){ $conf = array( "host" => "localhost", "username" => "root", "password" => "root", "dbname" => "db_bookworm", "port" => ini_get("mysqli.default_port"), "socket" => ini_get("mysqli.default_socket"), "prefix" => "bworm_" ); $cxn = new mysqli($conf["host"], $conf["username"], $conf["password"], $conf["dbname"]); if ($cxn->connect_errno){ \printf("connection failed: %s\n", $cxn->connect_error); exit(); } } function _destruct(){ mysqli_close($this); } }
i have error reporting on, , following error message given whenever attempt run code
warning: mysqli_prepare() expects parameter 1 mysqli, object given in \\moriarty\home\15\5cba2901\desktop\comp_proj\project\www\login.php on line 34
any clues on how fix this? have created connection class due how frequent opening connections, , figured it'd save time , grief on part. appreciated!
<?php /** change code : --------------------- db_cxn.php file --------------------- * */ class newconnection { static $cxn; function __construct() { $conf = array( "host" => "localhost", "username" => "root", "password" => "", "dbname" => "test", "port" => ini_get("mysqli.default_port"), "socket" => ini_get("mysqli.default_socket"), "prefix" => "" ); self::$cxn = mysqli_connect($conf["host"], $conf["username"], $conf["password"], $conf["dbname"]); if (self::$cxn->connect_errno) { \printf("connection failed: %s\n", self::$cxn->connect_error); exit(); } } function getconnection() { return self::$cxn; } function _destruct() { mysqli_close($this); }
}
Comments
Post a Comment