如下:php代码,求thinkjs如何创建数据库、数据表,以及(增、删、改、查)代码
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接错误: ' . mysql_error());
}
echo '连接成功<br />';
$sql = 'CREATE DATABASE RUNOOB';
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('创建数据库失败: ' . mysql_error());
}
echo "数据库 RUNOOB 创建成功\n";
mysql_close($conn);
?>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysql_error());
}
echo '连接成功<br />';
$sql = "CREATE TABLE runoob_tbl( ".
"runoob_id INT NOT NULL AUTO_INCREMENT, ".
"runoob_title VARCHAR(100) NOT NULL, ".
"runoob_author VARCHAR(40) NOT NULL, ".
"submission_date DATE, ".
"PRIMARY KEY ( runoob_id )); ";
mysql_select_db( 'RUNOOB' );
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('数据表创建失败: ' . mysql_error());
}
echo "数据表创建成功\n";
mysql_close($conn);
?>
扫码关注w3ctech微信公众号
用 query 方法,然后把创建数据表的 sql 语句传进去即可。
共收到1条回复