search

mysql常用命令
1、mysql -uroot -padmin --登录,用户名:root,密码:admin(自己设的)
2、show databases;显示数据库

PHP程序访问数据库

PHP程序访问数据库,完全可以使用存储过程,有人认为使用存储过程便于维护
不过仁者见仁,智者见智,在这个问题上,偶认为使用存储过程意味着必须要DBA和开发人员更紧密配合,如果其中一方更变,则显然难以维护。
但是使用存储过程至少有两个最明显的优点:速度和效率。
使用存储过程的速度显然更快。
在效率上,如果应用一次需要做一系列SQL操作,则需要往返于PHP与ORACLE,不如把该应用直接放到数据库方以减少往返次数,增加效率。
但是在INTERNET应用上,速度是极度重要的,所以很有必要使用存储过程。
偶也是使用PHP调用存储过程不久,做了下面这个列子。

代码:--------------------------------------------------------------------------------

//建立一个TEST表
CREATE TABLE TEST (
  ID        NUMBER(16)        NOT NULL,
  NAME      VARCHAR2(30)      NOT NULL,
  PRIMARY KEY (ID)
);

//插入一条数据
INSERT INTO TEST VALUES (5, 'PHP_BOOK');

//建立一个存储过程
CREATE OR REPLACE PROCEDURE PROC_TEST (
  p_id IN OUT NUMBER,
  p_name OUT VARCHAR2
) AS
BEGIN
  SELECT NAME INTO p_name
    FROM TEST
    WHERE ID = 5;
END PROC_TEST;
/

--------------------------------------------------------------------------------

PHP代码:--------------------------------------------------------------------------------


//建立数据库连接
$user = "scott";                //数据库用户名
$password = "tiger";            //密码
$conn_str = "tnsname";          //连接串(cstr : Connection_STRing)
$remote = true                  //是否远程连接
if ($remote) {
  $conn = OCILogon($user, $password, $conn_str);
}
else {
  $conn = OCILogon($user, $password);
}

//设定绑定
$id = 5;                        //准备用以绑定的php变量 id
$name = "";                     //准备用以绑定的php变量 name

/** 调用存储过程的sql语句(sql_sp : SQL_StoreProcedure)
 *  语法:
 *      BEGIN 存储过程名([[:]参数]); END;
 *  加上冒号表示该参数是一个位置
**/
$sql_sp = "BEGIN PROC_TEST(:id, :name); END;";

//Parse
$stmt = OCIParse($conn, $sql_sp);

//执行绑定
OCIBindByName($stmt, ":id", $id, 16);           //参数说明:绑定php变量$id到位置:id,并设定绑定长度16位
OCIBindByName($stmt, ":name", $name, 30);

//Execute
OCIExecute($stmt);

//结果
echo "name is : $name
";

?>


php连接mysql数据库

对于熟悉做网站的人来说,要想网站做成动态的,肯定要有数据库的支持,利用特定的脚本连接到数据库,从数据库中提取资料、向数据库中添加资料、删除资料等。这里我通过一个实例来说明如何用php连接到数据库的。

   我准备建立一个简单的通讯录,数据库的名字叫txl,数据库只有一个表叫personal_info,表中有5个字段
pi_id     pi_name     pi_tel     pi_qq     pi_email

   首先我们要创建数据库:
   create database txl;
   然后我们建立表
   CREATE TABLE `personal_info` (
  `pi_id` bigint(20) NOT NULL auto_increment,
  `pi_name` varchar(50) NOT NULL,
  `pi_tel` varchar(15) default NULL,
  `pi_qq` varchar(15) default NULL,
  `pi_email` varchar(50) default NULL,
  PRIMARY KEY  (`pi_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
上面的sql语句很简单,通过字面都能猜出什么意思。
下面是连接到数据库并且显示表personal_info的所有字段信息:
// connsql.php
    $mysql_server_name="localhost"; //数据库服务器名称
    $mysql_username="root"; // 连接数据库用户名
    $mysql_password="root"; // 连接数据库密码
    $mysql_database="lxr";  // 数据库的名字
  
    // 连接到数据库
    $conn=mysql_connect($mysql_server_name, $mysql_username,
                        $mysql_password);
  
    // 从表中提取信息的sql语句
    $strsql="select * from personal_info";
    // 执行sql查询
    $result=mysql_db_query($mysql_database, $strsql, $conn);
    // 获取查询结果
    $row=mysql_fetch_row($result);
  
    echo '';
    echo '

';

    // 显示字段名称
    echo "\n
\n";
    for ($i=0; $i     {
      echo '
\n";
    }
    echo "
\n";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "
\n";
      for ($i=0; $i       {
        echo '
';
      }
      echo "
\n";
    }
  
    echo "
'.
      mysql_field_name($result, $i);
      echo "
';
        echo "$row[$i]";
        echo '
\n";
    echo "
";
    // 释放资源
    mysql_free_result($result);
    // 关闭连接
    mysql_close(); 
?>
 
下面是运行结果:
pi_id     pi_name     pi_tel     pi_qq     pi_email
1     Zhangsan
    13911111111     642864125     zhangsan@126.com
2     Lisi
    13122222222     63958741     lisi@163.com
3     Wangwu
    13833333333     912345678     wangwu@sohu.com

所谓“万变不离其宗”,再复杂的操作也都是基于上面的来的,都少不了上面的基本的步骤,当需要时查一下相关的手册便可以解决。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP: The Foundation of Many WebsitesPHP: The Foundation of Many WebsitesApr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

Beyond the Hype: Assessing PHP's Role TodayBeyond the Hype: Assessing PHP's Role TodayApr 12, 2025 am 12:17 AM

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

What are Weak References in PHP and when are they useful?What are Weak References in PHP and when are they useful?Apr 12, 2025 am 12:13 AM

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

Explain the __invoke magic method in PHP.Explain the __invoke magic method in PHP.Apr 12, 2025 am 12:07 AM

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.