链接数据库

打开扩展  extension=php_pdo.dll

$pdo = new PDO("mysql:host=localhost;dbname=db_demo","root",""); $rs = $pdo -> query("select * from test"); while($row = $rs -> fetch()){ print_r($row);

$pdo = new PDO("mysql:host=localhost;dbname=db_demo","root",""); 
if($pdo -> exec("insert into db_demo(name,content) values('title','content')")){ 
echo "插入成功!"; 
echo $pdo -> lastinsertid(); 


php5.5 之后就已经不再支持mysql_connect 了

$dbname = 'zhuanfa'; $host = 'localhost'; $user = 'root'; $pwd = 'root'; $port = '3306'; $server = $this->db_mysql_hostname.':'.$this->db_mysql_port; $this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) or die('');
$this->conn = mysql_connect('localhost','root','root',true) or die('');
 mysql_select_db($this->db_mysql_database,$this->conn) or die('');   //选择数据库
mysql_query(
"set names " . $this->db_mysql_charset, $this->conn); //设置编码 utf-8



 

$host="localhost";
$user="root";
$password="abcdefg";
$conn=@mysql_connect($host,$user,$password);
if(!$conn)
{
die ("连接MYSQL服务器失败。".mysql_error());
}
else
{
echo "MYSQL服务器:$host <br>用户名称:$user <br>";
echo "连接MYSQL服务器成功。";
}

 

posted @ 2017-03-28 13:38  伊人世界  阅读(186)  评论(0编辑  收藏  举报
Fork me on GitHub