php mysql类函数

<p>class mysql{<br /> private $host;<br /> private $name;<br /> private $pass;<br /> private $table;<br /> private $ut;<br /> function __construct($host,$name,$pass,$table,$ut){<br /> $this-&gt;host=$host;<br /> $this-&gt;name=$name;<br /> $this-&gt;pass=$pass;<br /> $this-&gt;table=$table;<br /> $this-&gt;ut=$ut;<br /> $this-&gt;connect();<br /> <br /> }<br /> <br /> function connect(){<br /> $link=mysql_connect($this-&gt;host,$this-&gt;name,$this-&gt;pass) or die ($this-&gt;error());<br /> mysql_select_db($this-&gt;table,$link) or die(&quot;没该数据库:&quot;.$this-&gt;table);<br /> mysql_query(&quot;SET NAMES &#39;$this-&gt;ut&#39;&quot;);<br /> }<br /> <br /> function query($sql, $type = &#39;&#39;) {<br /> if(!($query = mysql_query($sql))) $this-&gt;show(&#39;Say:&#39;, $sql);<br /> return $query;<br /> }<br /> <br /> function show($message = &#39;&#39;, $sql = &#39;&#39;) {<br /> if(!$sql) echo $message;<br /> else echo $message.&#39;<br /> &#39;.$sql;<br /> }<br /> <br /> function affected_rows() {<br /> return mysql_affected_rows();<br /> }<br /> <br /> function result($query, $row) {<br /> return mysql_result($query, $row);<br /> }<br /> <br /> function num_rows($query) {<br /> return @mysql_num_rows($query);<br /> }<br /> <br /> function num_fields($query) {<br /> return mysql_num_fields($query);<br /> }<br /> <br /> function free_result($query) {<br /> return mysql_free_result($query);<br /> }<br /> <br /> function insert_id() {<br /> return mysql_insert_id();<br /> }<br /> <br /> function fetch_row($query) {<br /> return mysql_fetch_row($query);<br /> }<br /> <br /> function version() {<br /> return mysql_get_server_info();<br /> }<br /> <br /> function close() {<br /> return mysql_close();<br /> }<br /> <br /> //==============<br /> function fn_insert($table,$name,$value){<br /> <br /> $this-&gt;query(&quot;insert into $table ($name) value ($value)&quot;);<br /> <br /> }<br /> }<br /> <br /> $db = new mysql(&#39;localhost&#39;,&#39;root&#39;,&#39;&#39;,&#39;php100job_db&#39;,&quot;GBK&quot;);<br /> //$db-&gt;fn_insert(&#39;test&#39;,&#39;id,title,dates&#39;,&quot;&#39;&#39;,&#39;我插入的信息&#39;,now()&quot;);</p>
RangeTime:0.009255s
RangeMem:206.01 KB
返回顶部 留言