本文介绍了mysqli连接和oop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如果您使用$ _SERVER重新加载页面[''PHP_SELF''],您的程序 会在重新加载页面时丢失mysqli连接吗?这段代码 有用吗?我需要知道如何在方法之间进行连接。 我是OOP的新手?谢谢... 例子; ======================================== < ?php //网页 $ newsignon = new newuser(); 登录(); if(isset($ _ POST [''submit''])){ $ newsignon = query(" SELECT name,password FROM database") ; } ?> <?php // class newuser class newuser { public $ name; private $ passwd; private $ mysqli; 函数__construct(){ include(''dbconn.php''); $ mysqli = new mysqli($ dbnet,$ dbuser,$ dbpass,$ dbname); if(mysqli_connect_errno()){printf(无法连接到MySQL 服务器。错误代码:%s \\ \\ n",mysqli_connect_error()); 退出; } $ this-> mysqli = $ mysqli; //这是对的吗? } //结束构造函数 函数查询($ query){ if($ result) = $ this-> mysqli-> real_query($ query)){ $ result = $ this-> mysqli-> store_result(); if ($ this-> mysqli->错误){echo" ERROR with mysqli storage procedure" ;;} } //结束如果 } //结束函数 函数登录(){ echo"< form action =''"。$ _ POST [''PHP_SELF'' ]。'''method =''post''>" ;; //这会有效吗? echo"< input type ='' text''name =''user''/>< br />< input type =''password''name =''passwd''/>" ;; echo"< input type =''submit''value =''submit''/>" ;; } //结束功能 } //结束课If you do a page reload with $_SERVER[''PHP_SELF''] will your programlose a mysqli connection upon the reload of the page? Would this codework? I need to know how to carry over a connection between methods asI am new to OOP? Thanks...Example; ========================================<?php// webpage$newsignon = new newuser();logon();if (isset($_POST[''submit''])){$newsignon = query("SELECT name, password FROMdatabase");}?><?php// class newuserclass newuser {public $name;private $passwd;private $mysqli;function __construct(){include(''dbconn.php'');$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);if (mysqli_connect_errno()){ printf("Can''t connect to MySQLServer. Errorcode: %s\n", mysqli_connect_error());exit;}$this->mysqli = $mysqli; // is this right?} //end constructorfunction query($query){if ($result = $this->mysqli->real_query($query)){$result = $this->mysqli->store_result();if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}} // end if} // end functionfunction logon(){echo "<form action=''".$_POST[''PHP_SELF'']."'' method=''post'' >";// Would this work?echo "<input type=''text'' name=''user'' /><br /><inputtype=''password'' name=''passwd'' />";echo "<input type=''submit'' value=''submit'' />";} // end function} //end class推荐答案 _SERVER [''PHP_SELF''你的程序是否会在重新加载页面时丢失一个mysqli连接?这段代码 有用吗?我需要知道如何在方法之间进行连接。 我是OOP的新手?谢谢... 例子; ======================================== < ?php //网页_SERVER[''PHP_SELF''] will your programlose a mysqli connection upon the reload of the page? Would this codework? I need to know how to carry over a connection between methods asI am new to OOP? Thanks...Example; ========================================<?php// webpage newsignon = new newuser(); logon(); if(isset(newsignon = new newuser();logon();if (isset( _POST [''submit''])){_POST[''submit''])){ 这篇关于mysqli连接和oop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 07:16