php mysqlmysqliPDO (1) mysql, mysqlipdo
Original link: http://www.orlion.ga/1140/
The operations of the database at work are all encapsulated. I almost forgot how to use them, so I just wrote a blog to review them. If I forget again in the future, you can read this article.
Deprecated since PHP 5.5.0
1. mysql_connect()
resource mysql_connect([ string $server [, string $username [, string $password [, bool$new_link [, int $client_flags ]]]]] )
$server: The server address can include the port number. If the PHP directive mysql.default_host is not defined (the default), the default value is 'localhost:3306'. In SQL safe mode, the parameter is ignored and 'localhost:3306' is always used.
$username: username. The default value is defined by mysql.default_user. In SQL safe mode, the parameter is ignored and the username of the server process owner is always used.
$password: Password. The default value is defined by mysql.default_password. In SQL safe mode, the parameter is ignored and an empty password is always used.
$new_link: If mysql_connect() is called a second time with the same parameters, a new connection will not be established, but the already opened connection ID will be returned. Parameter new_link
changes this behavior and makes mysql_connect() always open a new connection, even when mysql_connect() has been called previously with the same parameters.
$client_flags: Use the following constants:
Constant | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MYSQL_CLIENT_COMPRESS |
Use compressed communication protocol | ||||||||||
MYSQL_CLIENT_IGNORE_SPACE |
Allow spaces after function names | ||||||||||
MYSQL_CLIENT_INTERACTIVE |
Allows setting the interactive_timeout time to wait idle before disconnecting (instead of wait_timeout). | ||||||||||
MYSQL_CLIENT_SSL |
Use SSL encryption. This flag is only available when MySQL client library version is 4.x or higher. Both PHP 4 and Windows versions of PHP 5 are bundled with 3.23.x.
|
2、mysql_close()
bool mysql_close ([ resource $link_identifier = NULL ] )
mysql_close() 关闭指定的连接标识所关联的到 MySQL 服务器的非持久连接。如果没有指定 link_identifier
,则关闭上一个打开的连接.通常不需要使用 mysql_close(),因为已打开的非持久连接会在脚本执行完毕后自动关闭。PHP 4 Zend 引擎引进了引用计数系统,可以自动检测到一个资源不再被引用了(和 Java 一样)。这种情况下此资源使用的所有外部资源都会被垃圾回收系统释放。因此,很少需要手工释放内存。
3、mysql_select_db()
bool mysql_select_db ( string $database_name [, resource $ link_identifier ] )
如果没有指定$link_identifier则使用上一个打开的数据库连接,如果没有打开的连接则将无参数调用mysql_connet()取得一个连接并使用。如果没有连接则E_WARNING错误
4、mysql_query()
resource mysql_query ( string $query [, resource $link_identifier = NULL ] )
$query查询字符串不应该以分号结束
$link_identifier如果不指定处理方式与mysql_select_db()相同。
返回值:
mysql_query() 仅对 SELECT,SHOW,DESCRIBE, EXPLAIN 和其他语句 语句返回一个 resource,如果查询出现错误则返回 FALSE
。对于其它类型的 SQL 语句,比如INSERT, UPDATE, DELETE, DROP 之类, mysql_query() 在执行成功时返回 TRUE
,出错时返回 FALSE
。返回的结果资源应该传递给 mysql_fetch_array() 和其他函数来处理结果表,取出返回的数据。假定查询成功,可以调用 mysql_num_rows() 来查看对应于 SELECT 语句返回了多少行,或者调用mysql_affected_rows() 来查看对应于 DELETE,INSERT,REPLACE 或 UPDATE 语句影响到了多少行。如果没有权限访问查询语句中引用的表时,mysql_query() 也会返回 FALSE
。
对于包含二进制数据的查询,你必须使用mysql_real_query()而不是mysql_query(),因为二进制代码数据可能包含“\0”字符,而且,mysql_real_query()比mysql_query()更快,因为它不会在查询字符串上调用strlen()。如果查询成功,函数返回零。如果发生一个错误,函数返回非零
5、mysql_affected_rows()
int mysql_affected_rows ([ resource $link_identifier = NULL ] )
取得最近一次与 link_identifier
关联的 INSERT,UPDATE 或 DELETE 查询所影响的记录行数。
6、mysql_fetch_array()
array mysql_fetch_array ( resource $result [, int $ result_type ] )
将结果以数组方式返回,一次只返回一行,然后指向下一行(用while循环取出)如果没有更多结果返回false。如果结果中有两个或两个以上的列有相同的字段名,最后一列将优先。如果sql中指定了别名则使用别名。PHP手册中指出mysql_fetch_array并不明显比mysql_fetch_row慢。
$result_type:可选:MYSQL_ASSOC(关联数组),MYSQL_NUM(枚举数组) 和 MYSQL_BOTH,默认值MYSQL_BOTH。
// MYSQL_NUM $result = mysql_query("SELECT id, name FROM mytable"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf ("ID: %s Name: %s", $row[0], $row[1]); } // MYSQL_ASSOC $result = mysql_query("SELECT id, name FROM mytable"); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { printf ("ID: %s Name: %s", $row["id"], $row["name"]); } // MYSQL_BOTH $result = mysql_query("SELECT id, name FROM mytable"); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { printf ("ID: %s Name: %s", $row[0], $row["name"]); }
7、其他函数:
string mysql_error ([ resource $link_identifier ] )
如果没有指定数据库连接则使用上一个连接,只返回最近一次mysql函数的错误文本。
bool mysql_set_charset ( string $charset [, resource $link_identifier = NULL ] )
设置字符集,数据库连接的选择与mysql_select_db()一样。
string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )
转义 SQL 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集(这是与mysql_escape_string()的不同)

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1
Easy-to-use and free code editor

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)