超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

php入門之連接mysql數(shù)據(jù)庫

時間:2025-12-03 08:31:53 php語言

php入門之連接mysql數(shù)據(jù)庫

  php入門之連接mysql數(shù)據(jù)庫的一個類,學習php的朋友可以參考下,希望對大家有所幫助!

  項目結構:

  運行效果;

  conn.php

  復制代碼 代碼如下:

  <?php

  class ConnectionMySQL{

  /pic/p>

  private $host="localhost";

  /pic/p>

  private $name="root";

  /pic/p>

  private $pass="";

  /pic/p>

  private $table="phptest";

  /pic/p>

  private $ut="utf-8";

  /pic/p>

  function __construct(){

  $this->ut=$ut;

  $this->connect();

  }

  /pic/p>

  function connect(){

  $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());

  mysql_select_db($this->table,$link) or die("沒該數(shù)據(jù)庫:".$this->table);

  mysql_query("SET NAMES '$this->ut'");

  }

  function query($sql, $type = '') {

  if(!($query = mysql_query($sql))) $this->show('Say:', $sql);

  return $query;

  }

  function show($message = '', $sql = '') {

  if(!$sql) echo $message;

  else echo $message.'<br>'.$sql;

  }

  function affected_rows() {

  return mysql_affected_rows();

  }

  function result($query, $row) {

  return mysql_result($query, $row);

  }

  function num_rows($query) {

  return @mysql_num_rows($query);

  }

  function num_fields($query) {

  return mysql_num_fields($query);

  }

  function free_result($query) {

  return mysql_free_result($query);

  }

  function insert_id() {

  return mysql_insert_id();

  }

  function fetch_row($query) {

  return mysql_fetch_row($query);

  }

  function version() {

  return mysql_get_server_info();

  }

  function close() {

  return mysql_close();

  }

  /pic/p>

  function fn_insert($table,$name,$value){

  $this->query("insert into $table ($name) value ($value)");

  }

  /pic/p>

  function fn_delete($table,$id,$value){

  $this->query("delete from $table where $id=$value");

  echo "id為". $id." 的記錄被成功刪除!";

  }

  }

  $db = new ConnectionMySQL();

  $db->fn_insert('test','id,name,sex',"'','hongtenzone','M'");

  $db->fn_delete('test', 'id', 1);

  ?>

【php入門之連接mysql數(shù)據(jù)庫】相關文章:

php連接mysql數(shù)據(jù)庫代碼09-13

php基礎之連接mysql數(shù)據(jù)庫和查詢數(shù)據(jù)02-24

PHP對數(shù)據(jù)庫MySQL的連接操作12-02

PHP腳本測試連接MySQL數(shù)據(jù)庫12-07

如何在PHP中連接MySQL數(shù)據(jù)庫07-11

PHP與MYSql連接與查詢11-30

PHP連接局域網(wǎng)MYSQL數(shù)據(jù)庫的技巧11-23

PHP連接MYSQL數(shù)據(jù)庫的3種常用方法03-01

php網(wǎng)站如何連接到遠程mysql數(shù)據(jù)庫11-28