Created
March 28, 2012 14:45
-
-
Save ryuichimatsumoto-single/2226769 to your computer and use it in GitHub Desktop.
Class for MySQL C0nnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
*MySQLの接続の為のクラス | |
*Class for connecting MySQL | |
*/ | |
class MySQL_Connect | |
{ | |
/* | |
*コンストラクタ | |
*@var url:パス | |
*@var user:ユーザー | |
*@var pass:パス | |
*@var db:データーベース名 | |
*/ | |
function __construct($url,$user,$pass,$db) | |
{ | |
$this->url = $url; | |
$this->user = $user; | |
$this->pass = $pass; | |
$this->db = $db; | |
} | |
/* | |
*DBの結果を配列で出力 | |
*@引数 tblname:テーブル名 | |
*/ | |
function MySQL_fetch_all($tblname) | |
{ | |
$link = mysql_connect($this->url,$this->user,$this->pass) or die("MySQLへの接続に失敗しました。"); | |
$sdb = mysql_select_db($this->db,$link) or die("データベースの選択に失敗しました。"); | |
//sql文 | |
$sql = "SELECT * FROM ".$tblname; | |
$result = mysql_query($sql, $link) or die("クエリの送信に失敗しました。<br />SQL:".$sql); | |
$data = array(); | |
$i=0; | |
while($rows = mysql_fetch_array($result)) | |
{ | |
$data[$i] = $rows; | |
$i++; | |
} | |
return $data; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
*MySQL呼び出し | |
*/ | |
include_once "MySQL_Connect.php"; | |
$url = "localhost"; | |
$user = "root"; | |
$pass =""; | |
$db = "******";//any words | |
$tblname ="***";//any words | |
$Connect = new MySQL_Connect($url,$user,$pass,$db); | |
print_r($Connect->MySQL_fetch_all($tblname)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment