mysql int取值范围与php intval区别

 更新时间:2016年11月25日 16:38  点击:2144

php教程 intval的取值范围:与操作系统相关,32位系统上为-2147483648到2147483647,64位系统上为-9223372036854775808到9223372036854775807。
mysql教程 int取值范围:与操作系统无关,为-2147483648到2147483647,无符号为0到4294967295。
mysql bigint取值范围:与操作系统无关,为-9223372036854775808到9223372036854775807,无符号为0到18446744073709551615。

操作时点击删除连接时就会会获取到当前条目的id然后程序获取到当前id进行删除操作。

<?php教程
       include("conn.php");
      
       $query = "select * from new order by id desc";
       $res = mysql教程_query($query);
       while($rows =mysql_fetch_array($res)){       //将查询到结果拆到$rows数组中
?>
<table>
       <tr>
              <td>标题:<?php echo$rows['title']?></td><td><a href="del.php?<?php $tid = $rows['id'] ?>">[删除]</a></td><td><a href="">[修改]</a></td>
       </tr>
<table>
       <?php
              }
       ?>
<form  action="addnews.php" method="post">
       作者:<input type="text" name="author"/><br/><br/>
       标题:<input type="text" name="title" size="20"><br/><br/>
       内容:<textarea name="content" cols="20" rows="20"></textarea>
       <input type="submit" value="提交" name="submit"/>
</form>

del.php代码

<?php
       $del = "delect from test where id in ($tid)";
       $res  = mysql_query($del);
       if($res){
              echo "删除成功";
       }else{
              echo "删除失败";
       }
?>

我一直是使用mysql教程这个数据库教程软件,它工作比较稳定,效率也很高。在遇到严重性能问题时,一般都有这么几种可能:

1、索引没有建好;
2、sql写法过于复杂;
3、配置错误;
4、机器实在负荷不了;

1、索引没有建好

如果看到mysql消耗的cpu很大,可以用mysql的client工具来检查。

在linux下执行

/usr/local/mysql/bin/mysql -hlocalhost -uroot -p

输入密码,如果没有密码,则不用-p参数就可以进到客户端界面中。

看看当前的运行情况

show full processlist

可以多运行几次

这个命令可以看到当前正在执行的sql语句,它会告知执行的sql、数据库名、执行的状态、来自的客户端ip、所使用的帐号、运行时间等信息

在我的cache后端,这里面大部分时间是看不到显示任何sql语句的,我认为这样才算比较正常。如果看到有很多sql语句,那么这台mysql就一定会有性能问题

public function insert($data)
{
if(isset($data['content'])&&!empty($data['content']))
{
$data_for_query['content'] = trim($data['content']);
}
else
{
return false;
}
if(isset($data['user_id'])&&!empty($data['user_id']))
{
$data_for_query['user_id'] = intval($data['user_id']);
}
else
{
return false;
}
$sql = "insert into `".$this->table_name."` (".$this->db->implodetocolumn(array_keys($data_for_query)).") values (".$this->db->implodetovalues(array_values($data_for_query)).")";
$this->db->query($sql);
$id = $this->db->lastinsertid();
if(empty($id))
{
return false;
}
else
{
return $id;
}
}

本文章提供了二款数据库教程连接实例,主要是讲php教程 mysql教程数据相关操作,有需要的朋友可以使用看看。

<?php
class mysql {
private $db_host; //主机地址
private $db_user; //用户名
private $db_pass; //连接密码
private $db_name; //名称
private $db_charset; //编码
private $conn;
public $debug=false;//调试开关,默认关闭
private $query_id; //用于判断sql语句是否执行成功
private $result; //结果集
private $num_rows; //结果集中行的数目,仅对select有效
private $insert_id; //上一步 insert 操作产生的 id
// 构造/析构函数
function __construct ($db_host,$db_user,$db_pass,$db_name,$db_charset,$conn) {
$this->db_host = $db_host ;
$this->db_user = $db_user ;
$this->db_pass = $db_pass ;
$this->db_name = $db_name ;
$this->db_charset = $db_charset ;
$this->conn = $conn ;
$this->connect();
}
function __destruct () {
@mysql_close($this->conn);
}
// 连接/选择数据库
public function connect () {
if ($this->conn == 'pconn') {
@$this->conn = mysql_pconnect($this->db_host,$this->db_user,$this->db_pass);
} else {
@$this->conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
}
if (!$this->conn) {
$this->show_error('数据库-连接失败:用户名或密码错误!');
}
if (!@mysql_select_db($this->db_name,$this->conn)) {
$this->show_error("数据库-选择失败:数据库 $this->db_name 不可用");
}
mysql_query("set names $this->db_charset");
return $this->conn;
}
// query方法
public function query ($sql) {
if ($this->query_id) $this->free_result();
$this->query_id = @mysql_query($sql,$this->conn);
if (!$this->query_id) $this->show_error("sql语句 <b>"$sql"</b> 执行时遇到错误");
return $this->query_id;
}
// 显示详细错误信息
public function show_error ($msg) {
if($this->debug){
$errinfo = mysql_error();
echo "错误:$msg <br/> 返回:$errinfo<p>";
}else{
echo '<p>出现错误!<p>';
}
}
// 获得query执行成功与否的信息
public function get_query_info($info){
if ($this->query_id) {
echo $info;
}
}
// 查询所有
public function findall ($table_name) {
$this->query("select * from $table_name");
}
// mysql_fetch_array
public function fetch_array () {
if ($this->query_id) {
$this->result = mysql_fetch_array($this->query_id);
return $this->result;
}
}
// ......
public function fetch_assoc () {
if ($this->query_id) {
$this->result = mysql_fetch_assoc($this->query_id);
return $this->result;
}
}
public function fetch_row () {
if ($this->query_id) {
$this->result = mysql_fetch_row($this->query_id);
return $this->result;
}
}
public function fetch_object () {
if ($this->query_id) {
$this->result = mysql_fetch_object($this->query_id);
return $this->result;
}
}
// 获取 num_rows
public function num_rows () {
if ($this->query_id) {
$this->num_rows = mysql_num_rows($this->query_id);
return $this->num_rows;
}
}
// 获取 insert_id
public function insert_id () {
return $this->insert_id = mysql_insert_id();
}
// 显示共有多少张表
public function show_tables () {
$this->query("show tables");
if ($this->query_id) {
echo "数据库 $this->db_name 共有 ".$this->num_rows($this->query_id)." 张表<br/>";
$i = 1;
while ($row = $this->fetch_array($this->query_id)){
echo "$i -- $row[0]<br/>";
$i ++;
}
}
}
// 显示共有多少个数据库
public function show_dbs(){
$this->query("show databases");
if ($this->query_id) {
echo "共有数据库 ".$this->num_rows($this->query_id)." 个<br/>";
$i = 1;
while ($this->row = $this->fetch_array($this->query_id)){
echo "$i -- ".$this->row[database]."<br />";
$i ++;
}
}
}
// 删除数据库:返回删除结果
public function drop_db ($db_name='') {
if ($db_name == '') {
$db_name = $this->db_name;//默认删除当前数据库
$this->query("drop database $db_name");
}else {
$this->query("drop database $db_name");
}
if ($this->query_id) {
return "数据库 $db_name 删除成功";
}else {
$this->show_error("数据库 $db_name 删除失败");
}
}
// 删除数据表:返回删除结果
public function drop_table ($table_name) {
$this->query("drop table $table_name");
if ($this->query_id) {
return "数据表 $table_name 删除成功";
}else {
$this->show_error("数据表 $table_name 删除失败");
}
}
// 创建数据库
public function create_db ($db_name) {
$this->query("create database $db_name");
if($this->query_id){
return "数据库 $db_name 创建成功";
}else {
$this->show_error("数据库 $db_name 创建失败");
}
}
// 获取数据库版本
public function get_info(){
echo mysql_get_server_info();
}
// 释放内存
public function free_result () {
if ( @mysql_free_result($this->query_id) )
unset ($this->result);
$this->query_id = 0;
}
} // end class
?>

下面提供一款自动选择数据库远程或本地连接代码

 

<?php
// 包含mysql操作类
include_once 'mysql.class.php';
// 本地mysql数据
$mysql_local_data = array('db_host'=>'localhost',
'db_user'=>'root',
'db_pass'=>'root',
'db_name'=>'test');
// 远程mysql数据
$mysql_remote_data = array('db_host'=>'61.183.41.178',
'db_user'=>'xxx',
'db_pass'=>'xxx',
'db_name'=>'xxx');
// 公用数据
$tb_prefix = 'php95_';
$db_charset = 'utf-8';
//本地连接成功则实例化本地mysql类,否则连接远程数据库并实例化mysql类
if (@mysql_connect($mysql_local_data[db_host], $mysql_local_data[db_user], $mysql_local_data[db_pass]))
$db = new mysql($db_host, $mysql_local_data[db_user], $mysql_local_data[db_pass], $mysql_local_data[db_name], $db_charset, $conn);
else
$db = new mysql($mysql_remote_data[db_host], $mysql_remote_data[db_user], $mysql_remote_data[db_pass], $mysql_remote_data[db_name], $db_charset, $conn);
$db->show_tables(); //测试:显示当前数据库下的所有表名
?>

假设我们要在test.php文件中操作虚拟主机的数据库,则首先要在本地调试,那么必然要连接本地、远程两个不同的数据库,问题:怎么让test.php自动识别当下该连接本地还是远程数据库呢?

[!--infotagslink--]

相关文章

  • mysql_connect与mysql_pconnect的区别详解

    在mysql中我们会看到有两种常用的数据库连接模式,一种是长久连接,另一各是页面访问完之后就断了连接,下面我来分别介绍mysql_connect与mysql_pconnect的区别,有需要了解...2016-11-25
  • C#中out与ref的区别实例解析

    这篇文章主要介绍了C#中out与ref的区别实例解析,对C#初学者有不错的学习借鉴价值,需要的朋友可以参考下...2020-06-25
  • PHP中func_get_args(),func_get_arg(),func_num_args()的区别

    复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04
  • 谈谈Jquery中的children find 的区别有哪些

    精华:find方法能找子孙,children方法只能找儿子一、Jquery中children 语法.children(selector) 说明expr是表达式,可选参数,所有选择器中的表达式都可以用在这,比如按标签名"div",按类名".class",按序号":first"等等,如果表...2015-10-21
  • PS中像素大小、文档大小的区别

    在PS中像素大小、文档大小有什么区别呢,这个估计很多初学者不清楚,下面我来给大家讲解一下,希望对你有帮助。 1、像素大小 通常用于显示屏显示的图片大小的调整。菜...2016-09-14
  • C#中sleep和wait的区别分析

    这篇文章主要介绍了C#中sleep和wait的区别分析,有助于深入理解C#中线程的原理与使用技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • uniapp和vue的区别详解

    这篇文章主要介绍了uniapp和vue的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-10-19
  • list与push的区别

    //函数list while(list($id,$username,$password,$add_date,$mdn,$mobile,$channel,$last_date,$area,$nickname) = mysql_fetch_array($rs)){ ...2016-11-25
  • input框中的name和id的区别

    这篇文章主要介绍了input框中的name和id的区别介绍,非常不错,具有参考借鉴价值,需要的朋友可以参考下...2016-11-22
  • 详解c#索引(Index)和范围(Range)

    这篇文章主要介绍了c#索引(Index)和范围(Range)的相关资料,帮助大家更好的理解和学习c#,感兴趣的朋友可以了解下...2020-12-08
  • php switch 与 if else 区别

    在php中switch是选择,if else也有同理,但是它们肯定是有区别的,那么我们来看看它们两者的区别在哪里呢,下面先看switch case语句吧。 switch($id){ case 1: ...2016-11-25
  • 浅谈C++中字符串输入get与getline的区别

    这篇文章主要介绍了C++中字符串输入get与getline的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
  • php mysql localhost,127.0.0.1和ip区别

    一家之言:localhost与127.0.0.1的区别 localhost与127.0.0.1的区别是什么?相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析。看来这个入门问题还有人不清楚,其实这两者是有区别的。no1:localhos...2014-05-31
  • C#中类与接口的区别个人总结

    这篇文章主要介绍了C#中类与接口的区别个人总结,本文讲解了类与接口的区别、接口的用处主要体现在下面几个方面、一些接口的疑问等内容,需要的朋友可以参考下...2020-06-25
  • 详解CSS3中nth-child与nth-of-type的区别

    这篇文章详细解析了CSS3中nth-child与nth-of-type的区别,有兴趣的同学可以参考一下 CSS3中nth-child与nth-of-type的区别其实很简单::nth-of-type为什么要叫:nth-of...2017-01-22
  • include包含头文件的语句中,双引号和尖括号的区别(详解)

    下面小编就为大家带来一篇include包含头文件的语句中,双引号和尖括号的区别(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-04-25
  • 英语单词state与status的区别

    state倾向于condition,是一种延续性的状态。status常用于描述一个过程中的某阶段(phase),类似于C语言中枚举型变量某一个固定的值,这个值属于一个已知的集合。这篇文章主要介绍了英语单词state与status的区别,需要的朋友可以参考下...2020-06-25
  • php echo print print_r三者区别分析

    php教程 echo print print_r三者区别分析 echo是PHP语句, print和print_r是函数,语句没有返回值,函数可以有返回值(即便没有用) print() 只能打印出简单类型变量的...2016-11-25
  • $i++ ++$i 运行速度与区别

    关于$i++与++$i是什么区别了,下面来看看这些区别的分别。 <?php 方式一: $begin = time(); $i = 0; while(++$i < 10000) { $j = 0; while(++$j < 10000)...2016-11-25
  • php strtr与str_replace区别比较

    php strtr与str_replace区别比较 函数都是具有替换字符功能的。但是strtr比str_replace性能上要块4倍。具体情况请 看如下分解: 首先是strtr函数: 实例1:当 以下为引用的...2016-11-25