Chinaunix首页 | 论坛 | 博客
  • 博客访问: 348911
  • 博文数量: 112
  • 博客积分: 5245
  • 博客等级: 大校
  • 技术积分: 1120
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-07 09:20
个人简介

静下来,定好方向,好好干。

文章分类
文章存档

2017年(1)

2012年(1)

2011年(5)

2010年(6)

2009年(16)

2008年(59)

2007年(24)

我的朋友

分类: PHP

2017-06-17 15:43:56

最近用PHP_MYSQL倒腾一个小应用,以下内容均源自互联网,收集备用。

location.href('')
">

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

// 定义变量并设置为空值
$name = $email = $gender = $comment = $website = "";


if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $website = test_input($_POST["website"]);
  $comment = test_input($_POST["comment"]);
  $gender = test_input($_POST["gender"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

PHP页面跳转:
header (location: "");

unset($_SESSION['username']);
unset($_SESSION['passcode']);
unset($_SESSION['userflag']);
echo "注销成功";
?>

$_GET['act'] == "logout"
 $conn = mysql_connect("127.0.0.1","root","") or die("数据库链接错误".mysql_error());  
 mysql_select_db("info_db",$conn) or die("数据库访问错误".mysql_error());  
 mysql_query("set names gb2312");  
?>  

create schema 是创建模式
create database 是创建数据库 


The documentation of MySQL says :
CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database. CREATE SCHEMA is a synonym for CREATE DATABASE as of MySQL 5.0.2.
So, it would seem normal that those two instruction do the same.

Now, SQL server allows the creation of different schema, which gives you the possibility of grouping tables that share a similar purpose. That helps to organize the database.

Schemas are not only for grouping. It is actually possible to give different permissions for each schema to different users, as described MSDN.

schema是一个名字空间,创建在某个database下的;一个database下可以包含多个schema。
schema的好处有三点:
1. 多个用户使用同一个数据库而不会相互影响。
2. 对数据库中的对象进行逻辑分组,更便于管理。
3. 各个应用分别使用各自的模式,以避免命名冲突。

ODBC 是一种应用程序编程接口(Application Programming Interface,API),使我们有能力连接到某个数据源(比如一个 MS Access 数据库)。


$conn=odbc_connect('northwind','','');
$sql="SELECT * FROM customers";
$rs=odbc_exec($conn,$sql);
odbc_fetch_row() 函数用于从结果集中返回记录。如果能够返回行,则函数返回 true,否则返回 false。
该函数有两个参数:ODBC 结果标识符和可选的行号:
odbc_fetch_row($rs)
odbc_result() 函数用于从记录中读取字段。该函数有两个参数:ODBC 结果标识符和字段编号或名称。
下面的代码行从记录中返回第一个字段的值:
$compname=odbc_result($rs,1);
下面的代码行返回名为 "CompanyName" 的字段的值:
$compname=odbc_result($rs,"CompanyName");
odbc_close($conn);

global 关键字用于函数内访问全局变量。
在函数内调用函数外定义的全局变量,我们需要在函数中的变量前加上 global 关键字:
$x=5;
$y=10;
 
function myTest()
{
    global $x,$y;
    $y=$x+$y;
}
 
myTest();
echo $y; // 输出 15
?>

PHP 将所有全局变量存储在一个名为 $GLOBALS[index] 的数组中。 index 保存变量的名称。
$x=5;
$y=10;
 
function myTest()
{
    $GLOBALS['y']=$GLOBALS['x']+$GLOBALS['y'];

 
myTest();
echo $y;
?>
当一个函数完成时,它的所有变量通常都会被删除。然而,有时候您希望某个局部变量不要被删除。
要做到这一点,请在您第一次声明变量时使用 static 关键字:
然后,每次调用该函数时,该变量将会保留着函数前一次被调用时的值。

Parse error: syntax error, unexpected '" "' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' 
==>
When you're working with strings in PHP you'll need to pay special attention to the formation, using " or '
$string = 'Hello, world!';
$string = "Hello, world!";
Both of these are valid, the following is not:
$string = "Hello, world';
You must also note that ' inside of a literal started with " will not end the string, and vice versa. So when you have a string which contains ', it is generally best practice to use double quotation marks.
$string = "It's ok here";
Escaping the string is also an option
$string = 'It\'s ok here too';


echo $row["id"] . " " . $row["name"]" ";
==>
echo $row["id"] . " " . $row["name"] ." ";

$sql = "insert into db.asset (name, project)
values(
'$project', 
'$name', 
)";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));

$sql = "select * from asset";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result))
{
echo "";
echo "". $row['id'] ."";
echo "". $row['name'] ."";
echo "". $row['project'] ."";
echo "";
}

?>

Select * from table limit 0,10
上面是一句很简单的mysql查询语句,它的作用是从一个名叫table的表里提取10条数据,并且把所有字段的值都获得。
其中的limit 0,10的用法是:limit 开始点,要提取的数目

$total=mysql_num_rows(mysql_query("select * from table")); //查询数据的总数total
$pagenum=ceil($total/$num);      //获得总页数 pagenum

$offset=($page-1)*$num;         //获取limit的第一个参数的值 offset ,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。             (传入的页数-1) * 每页的数据 得到limit第一个参数的值
$info=mysql_query("select * from table limit $offset,$num ");   //获取相应页数所需要显示的数据

For($i=1;$i<=$pagenum;$i++){
       $show=($i!=$page)?"":"$i";
       Echo $show." ";
}


var f = document.getElementById('form');

if(act == '上传') {
// 检查表单
if(!checkfun()) {
return;
}
f.action = 'upload_file.php';
} else {
// 检查表单
if(!checkfun()) {
return;
}
f.action = 'addmore.php';
}
f.submit();
}


Or:
    微信支付
    支付宝支付

    function wei(){
        document.pay.action="{:U('Home/Payment/getQrcode')}";
        document.pay.submit();
    }
    function zhi() {
        document.pay.action = "{:U('Home/Payment/doalipay')}";
        document.pay.submit();
    }


Or:
隐藏的表单项,同一个POST.

有些时候一个form里有多个提交按钮,怎样使程序能够分清楚到底用户是按那一个按钮提交上来的呢?我们就可以写一个隐藏域,然后在每一个按钮处加上onclick="document.form.command.value="xx""然后我们接到数据后先检查command的值就会知道用户是按的那个按钮提交上来的。
JavaScript不支持全局变量,但有时我们必须用全局变量,我们就可以把值先存在隐藏域里,它的值就不会丢失了。


//隐藏
document.getElementById('fm').style.display='none';
//显示
document.getElementById('fm').style.display='';


function setValues(){
var oTextbox1=document.getElementById("txt1");
var oTextbox2=document.getElementById("txt2");
oTextbox1.value="fitst textbox";
oTextbox2.value="second textbox";
}


//设置文本框中的字体颜色为灰色  
document.getElementById('test').style.color='#C0C0C0';  

$(function(){  
  $(".grayTips").each(function(){ //遍历每个文本框
    var objTextBox=$(this);
    var oldText=$.trim(objTextBox.val());
    objTextBox.css("color","#888"); 
    objTextBox.focus(function(){
      if(objTextBox.val()!=oldText){
        objTextBox.css("color","#000");
      }
      else{
        objTextBox.val("").css("color","#888");
      }
    });
    objTextBox.blur(function(){
      if(objTextBox.val()==""){
        objTextBox.val(oldText).css("color","#888");
      }
    });
    objTextBox.keydown(function(){
      objTextBox.css("color","#000");
    });
  });
});

将这段代码加载input 中!
value="你的提示文字" onFocus="if(value==defaultValue){value='';this.style.color='#000'}" onBlur="if(!value){value=defaultValue;this.style.color='#999'}" style="color:#999999"

连接到远程主机上的MYSQL。假设远程主机的IP为:110.110.110.110,用户名为root,密码为abcd123。则键入以下命  令:
  mysql -h110.110.110.110 -u root -p 123;(注:u与root之间可以不用加空格,其它也一样)

可以对已设计好的数据库,通过Export产生SQL语句用于创建同样的数据库。

需要使用session时在页面开始处写上session_start(); 之前不能有输出。
也可以在config.php等文件中加上session_start(); 在需要的地方加上include_once("config.php");
在PHP.INI里面设置session.auto_start就不用每页引用session_start()了

阅读(599) | 评论(0) | 转发(0) |
0

上一篇:一封写给自己的信

下一篇:没有了

给主人留下些什么吧!~~