<?phpfunction db_connect()
{
$result = new mysqli('localhost', 'root', '1212923456');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}?>
$result = new mysqli('localhost', 'root', '1212923456');这行报错内容是Fatal error: Class 'mysqli' not found in D:\AppServ\www\26\db_fns.php on line 5
{
$result = new mysqli('localhost', 'root', '1212923456');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}?>
$result = new mysqli('localhost', 'root', '1212923456');这行报错内容是Fatal error: Class 'mysqli' not found in D:\AppServ\www\26\db_fns.php on line 5
{
$result = new mysqli('localhost', 'root', '1212923456');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
}$conn=db_connect();
$result=$conn->query("insert into user values('whh94k','1212923456','[email protected]')");
?>
这样写向数据库增加记录杂没有反应啊 哪错了
另外
你这样连接是不对的
<?php function db_connect()
{
$result = new mysqli('localhost', 'root', '1212923456');
if (!$result)
throw new Exception('Could not connect to database server');
else
return $result;
} ?>
$result = new mysqli('localhost', 'root', '1212923456');因为你实现声明了一个函数,函数名为db_connect()
这个函数的工作思路是利用$result得到一个连接数据库的对象
如果非$re就抛出一个异常。否则返回连接后的
那么你应该在具体的应用时候
直接插入 db_connect();
即可