/**
* mysql读写分离
* edit: zj
*/
class db
{
public function __construct($sql)
{
$chestr = strtolower(trim($sql));
if(substr($chestr,0,6)=='select')
{
echo 'select db..
';
$link = mysql_connect("127.0.0.1:3306", "root", "root") or die("Could not connect: " . mysql_error());
mysql_select_db("test");
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQLI_ASSOC))
{
echo $row['username'].'
';
}
echo mysql_get_host_info($link).'
';
}
else
{
echo 'insert db..
';
$link = mysql_connect("localhost:3306","root","root") or die("Could not connect: " . mysql_error());
mysql_select_db("test");
mysql_query($sql);
echo @mysql_affected_rows().'
';
echo mysql_get_host_info($link).'
';
}
}
}
$write = new db(" update think_user set logintime='12345' where id=5");
$read = new db("SELECT * from think_user");