PHP2MySQL.php
Example table
# table example
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(75) | YES | | NULL | |
| country | varchar(75) | YES | | NULL | |
+---------+-------------+------+-----+---------+----------------+
Constructor
- Parameters
- $getUrl : MySQL Server URL or IP
- $getPort : MySQL Service Port
- $getDB : used database
- $getTB : used table
- $getUser : access user
- $getPwd : user password
public function __construct($getUrl, $getPort, $getDB, $getTB, $getUser, $getPwd)
API
public function select($getSelItem, $getConds)
public function insert($getInsertData)
public function execdelete($getConds)
public function update($getData, $getConds)
- advanced SQL : support complex sql command
public function execsql($sqlCmd, $existRetData, $paramDataArray)
Example
$obj = new PHP2MySQL("localhost","3306","test","cityData","test01","test01");
$getRes = $obj -> select(array("country"), array("name" => "shanghai"));
echo "select : ".$getRes["state"]." ".$getRes["info"]."<br>";
foreach($getRes["data"] as $key => $value) {
echo $key."->".$value."<br>";
}
$obj = new PHP2MySQL("localhost","3306","test","cityData","test01","test01");
$getRes = $obj -> insert(array("name" => "New York", "country" => "U.S.A."));
echo "insert : ".$getRes["state"]." ".$getRes["info"]."<br>";
$obj = new PHP2MySQL("localhost","3306","test","cityData","test01","test01");
$getRes = $obj -> execdelete(array("name" => "New York"));
echo "delete : ".$getRes["state"]." ".$getRes["info"]."<br>";
$obj = new PHP2MySQL("localhost","3306","test","cityData","test01","test01");
$getRes = $obj -> update(array("country" => "China"), array("name" => "shanghai"));
echo "update : ".$getRes["state"]." ".$getRes["info"]."<br>";
- execsql example (complicated SQL)
$obj = new PHP2MySQL("localhost","3306","employees","","test01","test01");
$getRes = $obj -> execsql(
"select dm.*, dp.dept_name from dept_manager as dm left outer join departments as dp on dm.dept_no = dp.dept_no where dm.from_date > :from_date order by dm.from_date asc;",
True,
array(':from_date' => '1990-01-01')
);
echo "select : ".$getRes["state"]." ".$getRes["info"]."<br>";
foreach($getRes["data"][0] as $key => $value) {
echo $key."->".$value."<br>";
}