无法用php连接数据库

时间:2014-03-05 21:21:08

标签: php

为什么我无法连接到数据库?

  

解析错误:第14行的C:\ xampp2 \ htdocs \ tutorials \ abc.php中的语法错误,意外的'mysql_query'(T_STRING)

<?php


$user = 'root' ; 
$pass = 'gfcf' ; 

$db = 'testdb' ; 

$con = new mysql('localhost', $user , $pass , $db) or die("UNABLE TO CONNECT");

$selected = mysql_select_db($db,con) 


mysql_query(" CREATE TABLE people 
(

firstname varchar(15)

gender varchar()


)");



?>

1 个答案:

答案 0 :(得分:1)

你正在混合mysql和mysqli函数:

$con = new mysqli('localhost', $user , $pass , $db) or die("UNABLE TO CONNECT");
$selected = mysqli_select_db($con,$db) 
mysqli_query($con, " CREATE TABLE people 
(
  firstname varchar(15)
  gender varchar()
)");