本文目录一览:
php代码操作mysql数据库
form method=”post” action=”18.3_index.php” input type=”hidden” name=”savepost” value=”1″ / table width=”490″ height=”180″ border=”0″ cellpadding=”0″ cellspacing=”0″ tr td width=”490″ align=”center” height=”40″ colspan=”2″添加公告信息/td /tr tr td width=”90″ align=”center”公告主题:/td td width=”400″ height=”30″ align=”left” input name=”txt_title” type=”text” id=”txt_title” size=”40″ / * /td /tr tr td width=”90″ align=”center”公告内容:/td td width=”400″ height=”80″ align=”left”textarea name=”txt_content” id=”txt_content” cols=”50″ rows=”4″/textarea/td /tr tr td width=”490″ height=”30″ colspan=”2″ align=”center” input name=”submit1″ type=”submit” class=”btn_grey” value=”保存” onClick=”return check(form1)” / input name=”submit2″ type=”reset” value=”重置” / /td /tr /table /form ?php if (isset($_POST[‘savepost’]) $_SERVER[‘REQUEST_METHOD’] == ‘POST’) { $conn=mysql_connect(‘localhost’,’root’,”) or die
php连接mysql代码怎么使用
1、首先,新建一个php_mysql.php的文件
2、其次,查看mysql服务是否打开,或者客户端的mysql能够正常打开。
鼠标右键电脑–》管理–》服务和应用程序–》服务–》找到mysql服务,看看是不是启用状态。
看看能不能打开客户端。
3、如果上面的可以了,那么就进入正题了,php连接mysql代码实例。
4、最后运行这个文件,看看运行结果吧。
怎么使用php代码建立mysql数据库
$link = mysql_pconnect(“localhost”,”root”,””);
$sql = ‘CREATE DATABASE my_db’;
if (mysql_query($sql, $link)) {
echo “成功”;
} else {
echo “失败” . mysql_error() . “\n”;
}
注:不提倡使用函数mysql_create_db()。最好用mysql_query()来提交一条SQLCREATEDATABASE语句来替代。
求PHP对MYSQL的简单操作代码!
?php
$db=mysql_connect(“host”,”dbuser”,”password”); //连接数据库服务器
mysql_select_db(“dbname”,$db); //选择数据库
mysql_query(“set names gbk”); //统一字符集
//查询示例:
$sql=”select * from tablename where condition”; //构造查询语句
$result=mysql_query($sql,$db); //在先前选中的数据库中执行查询操作
//从查询结果集中取一行输出,直至所有行输出完毕
while($myrow=mysql_fetch_array($result))
{
print_r($myrow);
}
//插入示例:
$sql=”insert into tablename values (‘field1′,’field2’,…….)”; //构造插入语句
$result=mysql_query($sql,$db); //执行插入
if ($result)
{
echo “插入成功!”;
exit;
}
else
{
echo “插入失败!”;
exit;
}
//修改、删除都是类似的,不再噜嗦
?
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/237755.html