<?php
$dsn = "mysql:host=localhost;dbname=test";
$db = new PDO($dsn, 'root', '');
$count = $db->exec("INSERT INTO foo SET name = 'heiyeluren',gender='男',time=NOW()");
echo $count;
$db = null;
?>这个代码是对test数据库 插入数据 但怎么创建test数据库呢。。
$dsn = "mysql:host=localhost;dbname=test";
$db = new PDO($dsn, 'root', '');
$count = $db->exec("INSERT INTO foo SET name = 'heiyeluren',gender='男',time=NOW()");
echo $count;
$db = null;
?>这个代码是对test数据库 插入数据 但怎么创建test数据库呢。。
$con = mysql_connect("localhost","value","value");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE text",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>看看
$db = new PDO($dsn, 'root', '');
$db->query('create database test');