English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
以下の例:
<?php class DBDA { public $host="localhost"; public $uid = "root"; public $pwd = "123"; public $dbname = "mydb"; //メンバーメソッド public function Query($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $r = $db->query($sql); if($type==1) { return $r->fetch_all(); } else { return $r; } } //文字列を返す方法 public function StrQuery($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $r = $db->query($sql); if($type==1) { $attr = $r->fetch_all(); $str = ""; foreach($attr as $v) { $str .= implode("^",$v)."|"; } return substr($str,0,strlen($str)-1); } else { return $r; } } //JSONを返す function JSONQuery($sql,$type=1) { $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); $r = $db->query($sql); if($type==1) { return json_encode($r->fetch_all(MYSQLI_ASSOC)); } else { return $r; } } }
以上のPHPのエンコードされたAjax文字列とJSON配列のメソッドは、編集者が皆さんに提供するすべての内容です。皆さんに参考になれば幸いですし、呐喊教程を多くのサポートをお願いします。