Home  >  Article  >  Backend Development  >  请问如何用PHP代码向mysql里的一个数据库添加一张新表

请问如何用PHP代码向mysql里的一个数据库添加一张新表

WBOY
WBOYOriginal
2016-06-23 14:03:01952browse


$con = mysql_connect('localhost','abc','123');
mysql_select_db('sjk');
$sql="CREATE TABLE test(Age int))";
mysql_query($sql,$con);
mysql_close($con);
echo "表已经创建好了.";
?>

小弟实验了以上代码
在浏览器里已经显示"表已经创建好了."
但是用phpMyAdmin打开sjk时
却没有发现test这个表

请问为什么呢?
要如何才能正常的添加一张表到数据库里呢?


回复讨论(解决方案)

use database

$sql="CREATE TABLE test(Age int)"; //多了一个右括号

$con = mysql_connect('localhost','abc','123');
mysql_select_db('sjk');
$sql="CREATE TABLE test(Age int))";----------?有错误的地方
mysql_query($sql,$con); 
mysql_close($con);
echo "表已经创建好了."; 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn