我正在尝试使用 xampp php myAdmin 连接 mysql。
默认情况下,用户root
在 mysql db 中。
这是我的代码:
<html>
<body>
<?php
$dbCon=@mysql_connect("localhost", "root", '');
if (!$dbCon)
{
echo('<p> '.mysql_error().'</p>');
exit();
}
else
{
if(!@mysql_select_db("crs",$dbCon))
{
die( "<p>".mysql_error()."</p>");
}
}
$qry="Create Table Courses( cCode VarChar(5) Not NULL Primary Key, cTitle VarChar(50) Not NULL, CH INT)";
if(@mysql_query($qry))
{
echo('<p>Courses Table has been created</p>');
}
else
{
echo('<p>Courses Table can not be created due to' .mysql_error(). '</p>');
}
$qry="Insert INTO Courses Values('C001','Intro to computing',4)";
if (@mysql_query($qry))
{
echo('<p>C001 is inserted </p>');
}
else
{
echo('<p>Courses Table cannot be created due to'.mysql_error().'</p>');
}
$qry="Insert INTO Courses Values ('C002', 'Programming Fundamentals',4), ('C003', 'Object Oriented Programming',4), ('C004', 'Operating Systems',4), ('C005', 'Data Structures and Algorithms',4)";
if(@mysql_query($qry))
{
echo('<p>4 Rows have been inserted</p>');
}
else
echo('<p>Multiple Rows cant be inserted due to'.mysql_error().'</p>')
?>
</body>
</html>