首页 > 编程技术 > php

mysql php 简单数据查询代码

发布时间:2016-11-25 15:58

$id = PostGet('cid');
if( !intval( $id ) )

 exit('aa');
}
else
{
 $Db = new Db();
 $sql ="Select address from cn_loupan_city where id='$id'";
 $query = $Db->query( $sql );
 $row = $Db->fetch( $query ); 
}
这查先把查询过来的值保存到一个数据$row中,再进行赋值,上的是一个mysql查询类,如果new db() $Db->query(),这些都是mysql_query()

function funcUrl($str)//url正则表达试
 {
  return (preg_match("/^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*([^<>""])*$/",$str))?true:false;
 }

if( $_POST)
{
 if( funcUrl( $_POST['url'] ) )
 {
  echo $_POST['url'];
 }
 else
 {
  exit('不是有效url');
 }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>网址 url 正则表达式实例</title>
</head>

<body>
<form id="111cnNet" name="111cnNet" method="post" action="">

<input name="url" type="text"  />
<input name="" type="submit"   value="提交 "/>
</form>

输入http://down.111cn.net教程
输出http://down.111cn.net

输入 qqq
输出 不是有效url
</body>
</html>

是获取表单的数据再用update更新到mysql教程数据库教程
if( $_POST )
{
 $cid = PostGet('cid',1);
 $address = PostGet('address',1);
 $sql = "Update cn_loupan_city set address='$address' where id='$cid'";
 $Db = new Db();
 if( $Db->query( $sql ))
 {
  MessAge('修改成功');
 }
 else
 {
  MessAge('操作失败,稍后再试!');
 }
 unset( $Db );
}

<table width="64%" border="0" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="s.php教程">
  <tr>
    <td><input type="hidden" name="cid" value="<?=$id?>">

  <textarea name="address" cols="60" rows="10" id="address"><?=iconv('GB2312', 'UTF-8', $row['address']); ?></textarea></td>
  </tr>
  <tr>
    <td height="31"><input type="submit" name="Submit" value="保存修改"></td>
  </tr>
  </form>
</table>

  echo "<table border='1'>";
  echo "<tr>";
  echo "<th>personID</th>";
  echo "<th>FirstName</th>";
  echo "<th>LastName</th>";
  echo "<th>Age</th>";
  echo "</tr>";
  $connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath("SpiderResult.mdb");
  $conn=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );
  $query=odbc_do($conn,"select top 10 * from content");
  while(odbc_fetch_row($query)) {
  
   echo "<tr>";
   $personID = odbc_result($query,1);
  
   $FirstName = odbc_result($query,2);
   $LastName = odbc_result($query,3);
   $Age = odbc_result($query,4);
   echo "<td>" . $personID . "</td>";
   echo "<td>" . $FirstName . "</td>";
   echo "<td>" . $LastName . "</td>";
   echo "<td>" . $Age . "</td>";
   echo "</tr>";
  }
  echo "</table>";
  odbc_close($conn);
  //本站原创www.111cn.net

 //要想让php与pdo  就必须在php.ini里面修改一个参数把extension=php_pdo.dll ";"去了。
 //
  $path ="d:pdoddSpiderResult.db3";
  $conn = new PDO("sqlite:$path");
  $array=array('','',''); 
 
  if( $conn )
  {
   echo ('pdo 连接正常connection pdo success');
  }
  else
  {
   echo ('pdo php cnnection pdo fail ,plase check database server!');
  }
  foreach ($conn->query('SELECT * FROM content limit 0,1') as $row)
  {
   
   print_r($row);
   die();
  }
  //本站原创www.111cn.net

标签:[!--infotagslink--]

您可能感兴趣的文章: