首页 > 网络基础知识

phpmanual php->是什么意思

phpmanual php->是什么意思

php中最基本的语法格式有些不懂

为了避免误人子弟,我反复查阅资料,给出以下回答。

echo实际上不是一个函数,它是一个命令,所以是不需要括号的,但是PHP支持加上括号的写法。

参考:*cn.php*/manual/zh/function.echo.php

print与 echo是一样的,毫无差别。PHP官方的解释是,echo比 print快一点点。

参考:*cn.php*/manual/zh/function.print.php

print_r是格式化输出,它可以打印数组和对象。你用print打印一个数组将始终输出array,而使用print_r将能输出整个数组的结构。

参考:*cn.php*/manual/zh/function.printf.php

\n是换行符的意思,输出后文本将被换行。还有\r(回车符)、\t(制表符)等这些不可视的字符。

你问的第三点好像写错了,应该是

$arr=array(10,1,5,2=>8,5=>15,18);

=>运算符指示数组的元素值(参考:*apps.hi.baidu*/share/detail/19910637)

2=>8的意思就是第二号元素的值为8,数组中原来第二号元素的值将被取代。

最终print_r($arr)的时候

Array

(

[0]=> 10

[1]=> 1

[2]=> 8

[5]=> 15

[6]=> 18

)

下标为 2的元素值 5被 8取代,4下标被 5=>15强制跳过。

php 中关于 html 字符转换问题

一、你上面要转换的两个字符串有区别吗,我怎么看不出来。

二、PHP自动把提交的敏感字符转换为html代码会给你编程减少许多麻烦,PHP4、PHP5都有这个功能,在php.ini里面控制,magic_quotes_gpc= On就表示自动转换,改为Off就关闭这个功能。

see manual是什么意思

see manual:参见手册。

网络释义:见手册。

例句:

To find values for these settings, see your network adapter manual, or ask your system administrator.

要查找这些设置的值,请参阅网络适配器手册或洽询系统管理员。扩展资料

双语例句:

1、See instruction manual before setting temperature at water heater.

在人工设定热水器水温之前请仔细阅读说明书。

2、See the manual pages for further information( man lilo).

参阅手册页以获得更进一步的信息(man lilo)。

3、Also see separate manual"Safety Information, Transport, Installation and Connection"-Appropriate Use.

请另见“安全信息,运输,安装及连接”须知–正确应用。

4、See the manual page( man chkconfig) for further details.

详细信息请参考手册页(man chkconfig)。

5、See the manual that came with your printer for specific installation and setup directions.

有关特定安装和设置说明,请参阅打印机附带的`手册。

6、For more information on this file, see the manual pages of krb5.conf.

有关此文件的更多信息,请参看krb5.conf的手册页。

7、See also the manual windows installation instructions.

参见手工windows安装指南。

8、See the grub manual for complete information.

若要全面和完整的信息,请参阅grub的手册。

9、See the CPP manual for more information.

更多的信息可以参考CPP手册。

10、See the PHP manual on variable referencing for an in-depth explanation.

请参阅PHP手册中的传参考呼叫以便取得更深入的解释。

11、See the GDB manual for a list of commands.

参见GDB手册了解命令列表。

12、See the exhibitor manual for the charging reserved for hotel.

预定宾馆收费可见参展商手册。

13、For a complete list of options, see the pam namespace manual page.

要获得完整的选项列表,请查看pam namespace手册页。

14、See workshop equipment manual, chapter on commercially *ailable tools, no.32-1.

参见《车间设备手册》,关于商用工具的章节,编号32-1。

15、See the FindBugs manual for more details.

更多细节请参阅FindBugs手册。

16、Please see the user's manual for a more thorough explanation.

请看用户使用手册来获取更多信息。

17、See the equipment operating manual for more detailed information on the fault code and corrective actions.

查看设备运行手册从故障代号得到更详细的信息和修复方法。

18、See Cayenne driver's manual, chapter entitled"spare wheel".

请参见《cayenne驾驶员手册》中标题为“备胎”的章节。

php安装的问题,无法载入 mysql 扩展,请检查 PHP 配置

首先你需要将PHP安装目录下的php_mysql.dll和php_mysqli.dll(我的在D:\apptools\php5\ext目录下)复制到c:\windows\system32目录下,然后修改php.ini文件(需要放到c:\windows目录下),关键是extension=php_mysql.dll和extension_dir="D:/apptools/php5/ext"。

我的配置是这样的:

[PHP]

;;;;;;;;;;;

; WARNING;

;;;;;;;;;;;

; This is the default settings file for new PHP installations.

; By default, PHP installs itself with a configuration suitable for

; development purposes, and*NOT* for production purposes.

; For several security-oriented considerations that should be taken

; before going online with your site, please consult php.ini-recommended

; and *php*/manual/en/security.php.

;;;;;;;;;;;;;;;;;;;

; About php.ini;

;;;;;;;;;;;;;;;;;;;

; This file controls many aspects of PHP's beh*ior. In order for PHP to

; read it, it must be named'php.ini'. PHP looks for it in the current

; working directory, in the path designated by the environment variable

; PHPRC, and in the path that was defined in compile time(in that order).

; Under Windows, the compile-time path is the Windows directory. The

; path in which the php.ini file is looked for can be overridden using

; the-c argument in command line mode.

;

; The syntax of the file is extremely simple. Whitespace and Lines

; beginning with a semicolon are silently ignored(as you probably guessed).

; Section headers(e.g. [Foo]) are also silently ignored, even though

; they might mean something in the future.

;

; Directives are specified using the following syntax:

; directive= value

; Directive names are*case sensitive*- foo=bar is different from FOO=bar.

;

; The value can be a string, a number, a PHP constant(e.g. E_ALL or M_PI), one

; of the INI constants(On, Off, True, False, Yes, No and None) or an expression

;(e.g. E_ALL&~E_NOTICE), or a quoted string("foo").

;

; Expressions in the INI file are limited to bitwise operators and parentheses:

;| bitwise OR

;& bitwise AND

;~ bitwise NOT

;! boolean NOT

;

; Boolean flags can be turned on using the values 1, On, True or Yes.

; They can be turned off using the values 0, Off, False or No.

;

; An empty string can be denoted by simply not writing anything after the equal

; sign, or by using the None keyword:

;

; foo=; sets foo to an empty string

; foo= none; sets foo to an empty string

; foo="none"; sets foo to the string'none'

;

; If you use constants in your value, and these constants belong to a

; dynamically loaded extension(either a PHP extension or a Zend extension),

; you may only use these constants*after* the line that loads the extension.

;

;

;;;;;;;;;;;;;;;;;;;

; About this file;

;;;;;;;;;;;;;;;;;;;

; All the values in the php.ini-dist file correspond to the builtin

; defaults(that is, if no php.ini is used, or if you delete these lines,

; the builtin defaults will be identical).

;;;;;;;;;;;;;;;;;;;;

; Language Options;

;;;;;;;;;;;;;;;;;;;;

; Enable the PHP scripting language engine under Apache.

engine= On

; Enable compatibility mode with Zend Engine 1(PHP 4.x)

zend.ze1_compatibility_mode= Off

; Allow the<? tag. Otherwise, only<?php and<script> tags are recognized.

; NOTE: Using short tags should be *oided when developing applications or

; libraries that are meant for redistribution, or deployment on PHP

; servers which are not under your control, because short tags may not

; be supported on the target server. For portable, redistributable code,

; be sure not to use short tags.

short_open_tag= On

; Allow ASP-style<%%> tags.

asp_tags= Off

; The number of significant digits displayed in floating point numbers.

precision= 12

; Enforce year 2000 compliance(will cause problems with non-compliant browsers)

y2k_compliance= On

; Output buffering allows you to send header lines(including cookies) even

; after you send body content, at the price of slowing PHP's output layer a

; bit. You can enable output buffering during runtime by calling the output

; buffering functions. You can also enable output buffering for all files by

; setting this directive to On. If you wish to limit the size of the buffer

; to a certain size- you can use a maximum number of bytes instead of'On', as

; a value for this directive(e.g., output_buffering=4096).

output_buffering= On

; You can redirect all of the output of your scripts to a function. For

; example, if you set output_handler to"mb_output_handler", character

; encoding will be transparently converted to the specified encoding.

; Setting any output handler automatically turns on output buffering.

; Note: People who wrote portable scripts should not depend on this ini

; directive. Instead, explicitly set the output handler using ob_start().

; Using this ini directive may cause problems unless you know what script

; is doing.

; Note: You cannot use both"mb_output_handler" with"ob_iconv_handler"

; and you cannot use both"ob_gzhandler" and"zlib.output_compression".

; Note: output_handler must be empty if this is set'On'!!!!

; Instead you must use zlib.output_handler.

;output_handler=

; Transparent output compression using the zlib library

; Valid values for this option are'off','on', or a specific buffer size

; to be used for compression(default is 4KB)

; Note: Resulting chunk size may vary due to nature of compression. PHP

; outputs chunks that are few hundreds bytes each as a result of

; compression. If you prefer a larger chunk size for better

; performance, enable output_buffering in addition.

; Note: You need to use zlib.output_handler instead of the standard

; output_handler, or otherwise the output will be corrupted.

zlib.output_compression= Off

; You cannot specify additional output handlers if zlib.output_compression

; is activated here. This setting does the same as output_handler but in

; a different order.

;zlib.output_handler=

; Implicit flush tells PHP to tell the output layer to flush itself

; automatically after every output block. This is equivalent to calling the

; PHP function flush() after each and every call to print() or echo() and each

; and every HTML block. Turning this option on has serious performance

; implications and is generally recommended for debugging purposes only.

implicit_flush= Off

; The unserialize callback function will be called(with the undefined class'

; name as parameter), if the unserializer finds an undefined class

; which should be instantiated.

; A warning appears if the specified function is not defined, or if the

; function doesn't include/implement the missing class.

; So only set this entry, if you really want to implement such a

; callback-function.

unserialize_callback_func=

; When floats& doubles are serialized store serialize_precision significant

; digits after the floating point. The default value ensures that when floats

; are decoded with unserialize, the data will remain the same.

serialize_precision= 100

; Whether to enable the ability to force arguments to be passed by reference

; at function call time. This method is deprecated and is likely to be

; unsupported in future versions of PHP/Zend. The encouraged method of

; specifying which arguments should be passed by reference is in the function

; declaration. You're encouraged to try and turn this option Off and make

; sure your scripts work properly with it in order to ensure they will work

; with future versions of the language(you will receive a warning each time

; you use this feature, and the argument will be passed by value instead of by

; reference).

allow_call_time_pass_reference= On

;

; Safe Mode

;

safe_mode= Off

; By default, Safe Mode does a UID compare check when

; opening files. If you want to relax this to a GID compare,

; then turn on safe_mode_gid.

safe_mode_gid= Off

; When safe_mode is on, UID/GID checks are bypassed when

; including files from this directory and its subdirectories.

;(directory must also be in include_path or full path must

; be used when including)

safe_mode_include_dir=

; When safe_mode is on, only executables located in the safe_mode_exec_dir

; will be allowed to be executed via the exec family of functions.

safe_mode_exec_dir=

; Setting certain environment variables may be a potential security breach.

; This directive contains a comma-delimited list of prefixes. In Safe Mode,

; the user may only alter environment variables whose names begin with the

; prefixes supplied here. By default, users will only be able to set

; environment variables that begin with PHP_(e.g. PHP_FOO=BAR).

;

; Note: If this directive is empty, PHP will let the user modify ANY

; environment variable!

safe_mode_allowed_env_vars= PHP_

; This directive contains a comma-delimited list of environment variables that

; the end user won't be able to change using putenv(). These variables will be

; protected even if safe_mode_allowed_env_vars is set to allow to change them.

safe_mode_protected_env_vars= LD_LIBRARY_PATH

; open_basedir, if set, limits all file operations to the defined directory

; and below. This directive makes most sense if used in a per-directory

; or per-virtualhost web server configuration file. This directive is

;*NOT* affected by whether Safe Mode is turned On or Off.

;open_basedir=

; This directive allows you to disable certain functions for security reasons.

; It receives a comma-delimited list of function names. This directive is

;*NOT* affected by whether Safe Mode is turned On or Off.

disable_functions=

; This directive allows you to disable certain classes for security reasons.

; It receives a comma-delimited list of class names. This directive is

;*NOT* affected by whether Safe Mode is turned On or Off.

disable_classes=

; Colors for Syntax Highlighting mode. Anything that's acceptable in

;<span style="color:???????"> would work.

;highlight.string=#DD0000

;highlight*ment=#FF9900

;highlight.keyword=#007700

;highlight.bg=#FFFFFF

;highlight.default=#0000BB

;highlight.html=#000000

; If enabled, the request will be allowed to complete even if the user aborts

; the request. Consider enabling it if executing long request, which may end up

; being interrupted by the user or a browser timing out.

; ignore_user_abort= On

;

; Misc

;

; Decides whether PHP may expose the fact that it is installed on the server

;(e.g. by adding its signature to the Web server header). It is no security

; threat in any way, but it makes it possible to determine whether you use PHP

; on your server or not.

expose_php= On

;;;;;;;;;;;;;;;;;;;

; Resource Limits;

;;;;;;;;;;;;;;;;;;;

max_execution_time= 3000; Maximum execution time of each script, in seconds

max_input_time= 60; Maximum amount of time each script may spend parsing request data

memory_limit= 8M; Maximum amount of memory a script may consume(8MB)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Error handling and logging;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; error_reporting is a bit-field. Or each number up to get desired error

; reporting level

; E_ALL- All errors and warnings(doesn't include E_STRICT)

; E_ERROR- fatal run-time errors

; E_WARNING- run-time warnings(non-fatal errors)

; E_PARSE- compile-time parse errors

; E_NOTICE- run-time notices(these are warnings which often result

; from a bug in your code, but it's possible that it was

; intentional(e.g., using an uninitialized variable and

; relying on the fact it's automatically initialized to an

; empty string)

; E_STRICT- run-time notices, enable to h*e PHP suggest changes

; to your code which will ensure the best interoperability

; and forward compatibility of your code

; E_CORE_ERROR- fatal errors that occur during PHP's initial startup

; E_CORE_WARNING- warnings(non-fatal errors) that occur during PHP's

; initial startup

; E_COMPILE_ERROR- fatal compile-time errors

; E_COMPILE_WARNING- compile-time warnings(non-fatal errors)

; E_USER_ERROR- user-generated error message

; E_USER_WARNING- user-generated warning message

; E_USER_NOTICE- user-generated notice message

;

; Examples:

;

;- Show all errors, except for notices and coding standards warnings

;

;error_reporting= E_ALL&~E_NOTICE

;

;- Show all errors, except for notices

;

;error_reporting= E_ALL&~E_NOTICE| E_STRICT

;

;- Show only errors

;

;error_reporting= E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR

;

;- Show all errors except for notices and coding standards warnings

;

error_reporting= E_ALL&~E_NOTICE

; Print out errors(as a part of the output). For production web sites,

; you're strongly encouraged to turn this feature off, and use error logging

; instead(see below). Keeping display_errors enabled on a production web site

; may reveal security information to end users, such as file paths on your Web

; server, your database schema or other information.

display_errors= On

; Even when display_errors is on, errors that occur during PHP's startup

; sequence are not displayed. It's strongly recommended to keep

; display_startup_errors off, except for when debugging.

display_startup_errors= Off

; Log errors into a log file(server-specific log, stderr, or error_log(below))

; As stated above, you're strongly advised to use error logging in place of

; error displaying on production web sites.

log_errors= Off

; Set maximum length of log_errors. In error_log information about the source is

; added. The default is * and 0 allows to not apply any maximum length at all.

log_errors_max_len= *

; Do not log repeated messages. Repeated errors must occur in same file on same

; line until ignore_repeated_source is set true.

ignore_repeated_errors= Off

; Ignore source of message when ignoring repeated messages. When this setting

; is On you will not log errors with repeated messages from different files or

; sourcelines.

ignore_repeated_source= Off

; If this parameter is set to Off, then memory leaks will not be shown(on

; stdout or in the log). This has only effect in a debug compile, and if

; error reporting includes E_WARNING in the allowed list

report_memleaks= On

; Store the last error/warning message in$php_errormsg(boolean).

track_errors= Off

; Disable the inclusion of HTML tags in error messages.

; Note: Never use this feature for production boxes.

;html_errors= Off

; If html_errors is set On PHP produces clickable error messages that direct

; to a page describing the error or function causing the error in detail.

; You can download a copy of the PHP manual from **php*/docs.php

; and change docref_root to the base URL of your local copy including the

; leading'/'. You must also specify the file extension being used including

; the dot.

; Note: Never use this feature for production boxes.

;docref_root="/phpmanual/"

;docref_ext=.html

; String to output before an error message.

;error_prepend_string="<font color=ff0000>"

; String to output after an error message.

;error_append_string="</font>"

; Log errors to specified file.

;error_log= filename

; Log errors to syslog(Event Log on NT, not valid in Windows 95).

;error_log= syslog

;;;;;;;;;;;;;;;;;

; Data Handling;

;;;;;;;;;;;;;;;;;

;

; Note- track_vars is ALWAYS enabled as of PHP 4.0.3

; The separator used in PHP generated URLs to separate arguments.

; Default is"&".

;arg_separator.output="&"

; List of separator(s) used by PHP to parse input URLs into variables.

; Default is"&".

; NOTE: Every character in this directive is considered as separator!

;arg_separator.input=";&"

; This directive describes the order in which PHP registers GET, POST, Cookie,

; Environment and Built-in variables(G, P, C, E& S respectively, often

; referred to as EGPCS or GPC). Registration is done from left to right, newer

; values override older values.

variables_order="EGPCS"

; Whether or not to register the EGPCS variables as global variables. You may

; want to turn this off if you don't want to clutter your scripts' global scope

; with user data. This makes most sense when coupled with track_vars- in which

; case you can access all of the GPC variables through the$HTTP_*_VARS[],

; variables.

;

; You should do your best to write your scripts so that they do not require

; register_globals to be on; Using form variables as globals can easily lead

; to possible security problems, if the code is not very well thought of.

register_globals= On

; Whether or not to register the old-style input arrays, HTTP_GET_VARS

; and friends. If you're not using them, it's recommended to turn them off,

; for performance reasons.

register_long_arrays= On

; This directive tells PHP whether to declare the argv&argc variables(that

; would contain the GET information). If you don't use these variables, you

; should turn it off for increased performance.

register_argc_argv= On

; When enabled, the SERVER and ENV variables are created when they're first

; used(Just In Time) instead of when the script starts. If these variables

; are not used within a script, h*ing this directive on will result in a

; performance gain. The PHP directives register_globals, register_long_arrays,

; and register_argc_argv must be disabled for this directive to h*e any affect.

auto_globals_jit= On

; Maximum size of POST data that PHP will accept.

post_max_size= 8M

; Magic quotes

;

; Magic quotes for incoming GET/POST/Cookie data.

magic_quotes_gpc= On

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.

magic_quotes_runtime= Off

; Use Sybase-style magic quotes(escape' with'' instead of\').

magic_quotes_sybase= Off

; Automatically add files before or after any PHP document.

auto_prepend_file=

auto_append_file=

; As of 4.0b4, PHP always outputs a character encoding by default in

; the Content-type: header. To disable sending of the charset, simply

; set it to be empty.

;

; PHP's built-in default is text/html

default_mimetype="text/html"

;default_charset="iso-8859-1"

; Always populate the$HTTP_RAW_POST_DATA variable.

;always_populate_raw_post_data= On

;;;;;;;;;;;;;;;;;;;;;;;;;

; Paths and Directories;

;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX:"/path1:/path2"

;include_path=".:/php/includes"

;

; Windows:"\path1;\path2"

include_path=".;D:\apptools\php5\PEAR"

; The root of the PHP pages, used only if nonempty.

; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root

; if you are running php as a CGI under any web server(other than IIS)

; see documentation for security issues. The alternate is to use the

; cgi.force_redirect configuration below

doc_root=

; The directory under which PHP opens the script using/~username used only

; if nonempty.

user_dir=

; Directory in which the loadable extensions(modules) reside.

extension_dir="D:/apptools/php5/ext"

; Whether or not to enable the dl() function. The dl() function does NOT work

; properly in multithreaded servers, such as IIS or Zeus, and is automatically

; disabled on them.

enable_dl= On

php如何链接mysql

在能够访问并处理数据库中的数据之前,必须创建到达数据库的连接。

在 PHP中,这个任务通过 mysql_connect()函数完成。

工具原料:电脑+php+mysql

php链接mysql的方法如下:

方法一、

先做出如下假设(也适用与方法二和方法三)

$username=your_name;

$userpass=your_pass;

$dbhost=localhost;

$dbdatabase=your_database;

//生成一个连接

$db_connect=mysql_connect($dbhost,$username,$userpass) or die("Unable to connect to the MySQL!");

//选择一个需要*作的数据库

mysql_select_db($dbdatabase,$db_connect);

//执行MySQL语句

$result=mysql_query("SELECT id,name FROM user");

//提取数据

$row=mysql_fetch_row($result);

注意事项:代码注释已经说明了一切。不过这里还需要做一些补充。

①在mysql_connect()、mysql_select_db()等函数之前使用@(错误控制运算符),可以忽略掉系统产生的错误信息,然后用die()来自定义错误信息;

②提取数据的时候,除了上面的mysql_fetch_row,常见的还有mysql_fetch_assoc和mysql_fetch_array,具体差别请查阅PHP Manual;

③对于mysql_query()函数的返回值,如果执行的语句有返回值(如SELECT、SHOW、DESCRIBE等),则返回相应数据(成功时)或FALSE(失败时);如果执行的语句没有返回值(如DELETE、DROP、INSERT、UPDATE等),则返回TRUE(成功时)或FALSE(失败时)。

方法二、面向对象

其实这种方法和普通方法非常类似,只是把相应的函数换成了面向对象方法,直接看代码。

$db=new mysqli($dbhost,$username,$userpass,$dbdatabase);

if(mysqli_connect_error()){

echo'Could not connect to database.';

exit;

}

$result=$db->query("SELECT id,name FROM user");

$row=$result->fetch_row();

这里用到的是mysqli,意思就是mysql的扩展,既可以通过面向过程的方式也可以通过面向对象的方式与数据库进行交互,唯一不同的是调用函数(对象方法)的方式不一样。

方法三、PDO方法

PDO其实是PHP Database Objects的缩写,中文即PHP数据库对象。它提供了一种统一的PHP与数据库交互的方法。

这是目前流行的一种连接数据库的方法。它的优势在于:只要正确提供数据源,余下对于数据库的基本*作都是一样的。也就是说,同一段代码既可以同MySQL交互,也可以和SQLite3交互,当然也可以和PostgreSQL进行交互,前提是你提供了正确的数据源。下面看一下连接MySQL的代码:

$dsn='mysql:host='.$dbhost.';dbname='.$dbdatabase.';'

$dbh=new PDO($dsn,$username,$userpass);

如果是SQLite3,直接使用下面的代码:

$dsn='sqlite3:"C:\sqlite\user.db"';

$dbh=new PDO($dsn);

如果是PostgreSQL,下面的代码能够对付:

$dsn='pgsql:host='.$dbhost.' port=5432 dbname='.$dbdatabase.' user='.$username.' password='.$userpass;

$dbh=new PDO($dsn);

跟数据库成功建立连接之后,下面就只需要从数据库获取数据或*更新数据,实例代码如下:

$stmt=$dbh->query('SELECT id,name FROM user');

$row=$stmt->fetch();

综上所述有三种方法链接mysql

php及数据库

PHP调用三种数据库的方法

本文比较详细的介绍PHP调用MySQL、ODBC以及ORACLE数据库。

MySQL是一个小巧灵珑的数据库服务器软件,对于中、小型应用系统是非常理想的。除了支持标准的ANSI SQL语句外,最重要的是,它还支持多种平台,而在Unix/Linux系统上,MySQL支持多线程运行方式,从而能获得相当好的性能。它和PHP、 Apache一样,是属于开放源代码软件。其官方网站是:,上面提供Windows,Linux,Unix版本的源代码的下载。

注意,MySQL访问函数都需要有相应的权限才能运行。常用的相关函数介绍如下:

(1)integer mysql_connect(主机,用户名,口令);

此函数开始一个对指定主机上的MySQL数据库的连接。若该数据库位于一个不同地端口,则在主机名后加上冒号和端口号。所有参数均为可选的,缺省情况下分别对应为本地主机、用户正在执行的脚本名和空。主机可以是IP地址或域名。

在脚本执行结束时,连接被自动关闭,也可以用mysql_close提前关闭。

(2)boolean mysql_create_db(数据库名);

创建一个数据库。注意必须用一个带有创建数据库许可权的帐号打开连接。

(3)boolean mysql_select_db(数据库名,连接号);

选择缺省数据库。

(4)integer mysql_query(SQL语句,连接号);

对指定数据库进行查询。如果SQL语句是select,则返回一个结果号,否则返回的值可以不理会。如果失败,返回false.。

(5)array mysql_fetch_array(结果号);

取出下一行,返回一个数组.可以用数字下标访问(第一个字段是下标 0),也可以用字符串下标访问(即使用各字段名)。如已取了最后一行,返回 false.。

(6)mysql_fetch_row(结果号);

返回一个矩阵代表结果集中一行的所有域。每次调用都会产生下一行,直到没有行剩下时返回false。每个域值都由一个从零开始的偏移量索引。这是从查询中获取结果的最快方法。

(7)integer mysql_num_rows(结果号);

返回结果集中行的数目

(8)integer mysql_num_fields(结果号);

返回结果集中域的数目。

(9)integer mysql_list_dbs();

向服务器查询数据库列表。它返回一个结果指针,该指针可用于mysql_fetch_row函数及类似函数。

(10)mysql_list_tables(数据库名);

获取一个指向指定数据库的表单列表的结果指针。该结果指针可用于任何从结果集中获取行的函数。

(11)mysql_close(连接号);

关闭对数据库的连接。连接必须是由mysql_connect打开的。该函数的使用不是严格必需的,因为在脚本结束时,所有非永久链路都会被自动关闭。

(12)mysql_pconnect(主机,用户名,口令);

与mysql_connect完全相似,但建立一个"永久连接",该连接一经建立永不关闭,即使使用mysql_close函数或程序执行完毕也不关闭.下一次试图建立永久连接时,系统如发现已存在一个永久连接,则直接返回该连接号而不重新创建。

下面是一个调用MYSQL数据库并分页显示的例子。

<?

$pagesize= 5;//每页显示5条记录

$host="localhost";

$user="user";

$password="psw";

$dbname="book";//所查询的库表名;

//连接MySQL数据库

mysql_connect("$host","$user","$password") or die("无法连接MySQL数据库服务器!");

$db= mysql_select_db("$dbname") or die("无法连接数据库!");

$sql="select count(*) as total from pagetest";//生成查询记录数的SQL语句

$rst= mysql_query($sql) or die("无法执行SQL语句:$sql!");//查询记录数

$row= mysql_fetch_array($rst) or die("没有更多的记录!");/取出一条记录

$rowcount=$row["total"];//取出记录数

mysql_free_result($rst) or die("无法释放result资源!");//释放result资源

$pagecount= bcdiv($rowcount+$pagesize-1,$pagesize,0);//算出总共有几页

if(!isset($pageno)){

$pageno= 1;//在没有设置pageno时,缺省为显示第1页

}

if($pageno<1){

$pageno= 1;//若pageno比1小,则把它设置为1

}

if($pageno>$pagecount){

$pageno=$pagecount;//若pageno比总共的页数大,则把它设置为最后一页

}

if($pageno>0){

$href= eregi_replace("%2f","/",urlencode($PHP_SELF));//把$PHP_SELF转换为可以在URL上使用的字符串,这样的话就可以处理中文目录或中文文件名

if($pageno>1){//显示上一页的裢接

echo"<a href="".$href."?pageno=".($pageno-1)."">上一页</a>";

}

else{

echo"上一页";

}

for($i=1;$i<$pageno;$i++){

echo"<a href="".$href."?pageno=".$i."">".$i."</a>";

}

echo$pageno."";

for($i++;$i<=$pagecount;$i++){

echo"<a href="".$href."?pageno=".$i."">".$i."</a>";

}

if($pageno<$pagecount){//显示下一页的裢接

echo"<a href="".$href."?pageno=".($pageno+1)."">下一页</a>";

}

else{

echo"下一页";

}

$offset=($pageno-1)*$pagesize;//算出本页第一条记录在整个表中的位置(第一条记录为0)

$sql="select* from pagetest LIMIT$offset,$pagesize";//生成查询本页数据的SQL语句

$rst= mysql_query($sql);//查询本页数据

$num_fields= mysql_num_fields($rst);//取得字段总数

$i= 0;

while($i<$num_fields){//取得所有字段的名字

$fields[$i]= mysql_field_name($rst,$i);//取得第i+1个字段的名字

$i++;

}

echo"<table border="1" cellspacing="0" cellpadding="0">";//开始输出表格

echo"<tr>";

reset($fields);

while(list(,$field_name)=each($fields)){//显示字段名称

echo"<th>$field_name</th>";

}

echo"</tr>";

while($row=mysql_fetch_array($rst)){//显示本页数据

echo"<tr>";

reset($fields);

while(list(,$field_name)=each($fields)){//显示每个字段的值

$field_value=$row[$field_name];

if($field_value==""){

echo"<td></td>";

}

else{

echo"<td>$field_value</td>";

}

}

echo"</tr>";

}

echo"</table>";//表格输出结束

mysql_free_result($rst) or die("无法释放result资源!");//释放result资源

}

else{

echo"目前该表中没有任何数据!";

}

mysql_close($server) or die("无法与服务器断开连接!");//断开连接并释放资源

?>

开放数据库连接(ODBC)已成为一种与数据库进行通信的工业标准。PHP也提供了标准的接口,使得PHP能调用Access,SQL SERVER等数据库。其相关函数是:

(1)integer odbc_connect(string dsn, string user, string password)

连接到一个ODBC数据库源名字上。

(2)integer odbc_exec(integer connection, string query)或 odbc_do(integer connection, string query)

在一个连接上执行查询。

(3)boolean odbc_fetch_row(integer result, integer row)

从一个结果集中获取一行数据。Row参数是可选的,若为空缺,则返回下一个有效行。在结果集中不再剩余行时返回false。

(4)boolean odbc_close(integer connection)

关闭一个数据库的连接。若在该连接上有打开的事务,则返回一个错误,而且连接不会被关闭。

最后,还是看个分页的例子:

<?

//设定每页显示条数

$show_num= 10;

$spages=$pages;//避免$pages后期被改变

//定义连接

$dsn="localhost";

$user="sa";

$password="";

//计算总记录数

$rs_num="select count(*) as id from bbs where zu='0' and lei='".$lei."'";

$conn_id= odbc_connect($dsn,$user,$password);

$rnum= odbc_exec($conn_id,$rs_num);

while(odbc_fetch_row($rnum)){

$total_rs= odbc_result($rnum,"id");//将总记录数放入$total_rs变量

}

//计算与页有关的条数

$nnn=$total_rs/$show_num;//计算总页数

$hnnn= intval($nnn);//将总页数取整

$cnnnn=$nnn-$hnnn;

//计算所需总页数

switch($cnnn){

case"0":

$hnnn++;

$nnn=$hnnn;//总页数

break;

default:

$nnn=$hnnn;//总页数

break;

};

if($nnn== 0)$nnn++;

//计算页面改变所需的条件

$fore=$pages;

$next=$pages;

$fore-= 1;

$next+= 1;

if($fore> 0){

echo"<a>首页</a>";

echo"<a>前页</a>";

};

if($pages<$nnn){

echo"<a>后页</a>";

echo"<a>尾页</a>";

};

echo"共".$nnn."页";

$query_string="SELECT* FROM table where condition order by you wanted order";

$cur= odbc_exec($conn_id,$query_string);

//取到循环的顶部

$cnum=($pages-1)*$show_num;//计算当前的记录游标的位置

//空循环到显示记录游标处

if($cnum!= 0){

for($i=0;$i<=$cnum;odbc_fetch_row($cur));

};

$i=1;

//显示记录

while(odbc_fetch_row($cur)){

echo;

if($i==$show_num){//在不满页数时跳出程序

break;

};

$i++;

};

//关闭连接

odbc_close($conn_id);

?>

Oracle(甲骨文)是世界上最为流行的关系数据库。它是大*推崇的工业化的强有力的引擎。我们先看看其相关的函数:

(1)integer ora_logon(string user, string password)

开始对一个Oracle数据库服务器的连接。

(2)integer ora_open(integer connection)

打开给出的连接的游标。

(3)integer ora_do(integer connection, string query)

在给出的连接上执行查询。PHP生成一个指示器,解析查询,并执行之。

(4)integer ora_parse(integer cursor, string query)

解析一个查询并准备好执行。

(5)boolean ora_exec(integer cursor)

执行一个先前由ora_parse函数解析过的查询。

(6)boolean ora_fetch(integer cursor)

此函数会使得一个执行过的查询中的行被取到指示器中。这使得您可以调用ora_getcolumn函数。

(7)string ora_getcolumn(integer cursor, integer column)

返回当前的值。列由零开始的数字索引。

(8)boolean ora_logoff(integer connection)

断开对数据库服务器的链接。

以下是向ORACLE数据库*数据的示例程序:

<html>

<head><title>向ORACLE数据库中*数据</title></head>

<body>

<form action="<?echo$PHP_SELF;?>" method="post">

<table border="1" cellspacing="0" cellpadding="0">

<tr>

<th>ID</th>

<th>name</th>

<th>Description</th>

</tr>

<tr>

<td><input type="text" name="name" maxlength="50" size="10"></td>

<td><input type="text" name="email" maxlength="255" size="30"></td>

<td><input type="text" name="Description" maxlength="255" size="50"></td>

</tr>

<tr align="center">

<td colspan="3"><input type="submit" value="提交"><input type="reset" value="重写"></td>

</tr>

</table>

</form>

<?

//先设置两个环境变量ORACLE_HOME,ORACLE_SID

putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");

putenv("ORACLE_SID=ora8");

//设置网页显示中文

putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");

if($connection=ora_logon("scott","tiger")){

//库表test有ID,name,Description三项

$sql='insert into test(ID,name,Description) values';

$sql.='(''.$ID.'',''.$name.'',''.$Description.'')';

if($cursor=ora_do($connect,$sql)){

print("insert finished!");

}

$query='select* from test';

if($cursor=ora_do($connect,$query)){

ora_fetch($cursor);

$content0=ora_getcolumn($cursor,0);

$content1=ora_getcolumn($cursor,1);

$content2=ora_getcolumn($cursor,2);

print("$content0");

print("$content1");

print("$content2");

ora_close($cursor);

}

ora_logoff($connection);

}

?>

</body>

</html>

通过PHP你可以轻松的连接到数据库,请求数据并将其显示在你的web站点中,甚至修改数据库中的数据。 MySQL是一种很流行的数据库,并且在互联网中有许多有关PHP与MySQL的教程。MySQL是免费的,这一点也许就吸引了不少人。由于其广泛应用,我就不想在这里赘述MySQL的使用方法了。Oracle被大量在企业应用中采用,因此我们就利用Oracle来介绍PHP与数据库的连接。我们当然不会提及Oracle数据库的设计原理,原因是这已经超出了我们的讨论范围。

PHP提供了两套函数与Oracle连接,分别是ORA_和OCI函数。其中ORA_函数略显陈旧。OCI函数更新据说更好一些。两者的使用语法几乎相差无几。如前所述,你的PHP安装选项应该可以支持两者的使用。

想获得更多有关在Microsoft Windows平台上安装支持PHP3的Apache服务器的知识以及更多有关Oracle数据库的知识,请查阅以下URL:。

4.1连接

if($conn=Ora_Logon("user@TNSNAME","password"))

{

echo"SUCCESS! Connected to database\n";

}

else

{

echo"Failed:-( Could not connect to database\n";

}

Ora_Logoff($conn);

phpinfo();

?>

以上代码使用TNSNAME(在你的tnsnames.ora文件中指明)定义的Oracle数据库名称、用户名称和密码连接数据库。在成功连接的基础上,ora_logon函数返回一个非零的连接ID并储存在变量$conn中。

4.2查询

假设与数据库已经连接就绪,下面我们就来实际的应用对数据库的查询。下面的代码演示了一个连接并查询的典型例子:

/*

*连接数据库并执行查询

*/

function printoraerr($in_cur)

{

//检查Oracle是否出错

//如果存在错误则显示

//当指针被激活时每次请求Oracle后调用该函数

if(ora_errorcode($in_cur))

echo"Oracle code-".ora_error($in_cur)."\n";

return;

}

/**主程序*/

if(!($conn=ora_logon("user@TNSNAME","password")))

{

echo"Connection to database failed\n";

exit;

}

echo"Connected as connection-$conn

\n";

echo"Opening cursor…

\n";

$cursor=ora_open($conn); printoraerr($cursor);

echo"Opened cursor-$cursor

\n";

$qry="select user,sysdate from dual";

echo"Parsing the query$qry…

\n";

ora_parse($cursor,$qry,0); printoraerr($cursor);

echo"Query parsed

\n";

echo"Executing cursor…

\n";

ora_exec($cursor); printoraerr($cursor);

echo"Executed cursor

\n";

echo"Fetching cursor…

\n";

while(ora_fetch($cursor))

{

$user=ora_getcolumn($cursor,0); printoraerr($cursor);

$sysdate=ora_getcolumn($cursor,1); printoraerr($cursor);

echo" row=$user,$sysdate

\n";

}

echo"Fetched all records

\n";

echo"Closing cursor…

\n";

ora_close($cursor);

echo"Closed cursor

\n";

echo"Logging off from oracle…

\n";

ora_logoff($conn);

echo"Logged off from oracle

\n";

?>

(译者注:以上代码段缺少注释,请读者参考PHP Manual的Oracle数据库函数部分)

4.3显示结果

以下代码演示了怎样查询数据库并将结果输出:

function printoraerr($in_cur,$conn)

{

//检查Oracle是否出错

//如果存在错误则显示

//当指针被激活时每次请求Oracle后调用该函数

// If it encountered an error, we exit immediately

if(ora_errorcode($in_cur))

{

echo"Oracle code-".ora_error($in_cur)."

n";

ora_logoff($conn);

exit;

}

return;

}

function exequery($w_qry,$conn)

{

$cursor=ora_open($conn); printoraerr($cursor,$conn);

ora_parse($cursor,$w_qry,0); printoraerr($cursor,$conn);

ora_exec($cursor); printoraerr($cursor,$conn);

$numrows=0;

$w_numcols=ora_numcols($cursor);

//显示头部

echo"

\n";

for($i=0;$i<$w_numcols;$i++)

{

$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";

echo"\t".ora_columnname($cursor,$i)."\n";

}

echo"

\n";

while(ora_fetch($cursor))

{

echo"\n";

for($i=0;$i<$w_numcols;$i++)

{

$align=(ora_columntype($cursor,$i)=="NUMBER")?"RIGHT":"LEFT";

if(ora_columntype($cursor,$i)=="LONG")

echo"".

ora_getcolumn($cursor,$i)."

\n";

else

echo"".ora_getcolumn($cursor,$i)."\n";

printoraerr($cursor,$conn);

}

$numrows++;

echo"

\n";

}

if($numrows==0)

echo" Query returned no records

\n";

else

{

echo"\n";

echo" Count\n";

echo"$numrows\n";

echo"

\n";

}

echo"\n";

ora_close($cursor);

return;

}

//主程序

if(!($conn=ora_logon("user@SID","password")))

{

echo"Error: Cannot connect to database\n";

exit;

}

$qry="SELECT

deptno\"Dept\"

,empno\"Emp\"

,empnm\"Name\"

,salary\"Salary\"

FROM

employee

ORDER BY 1,2";

exequery($qry);

ora_logoff($conn);

?>

(译者注:以上代码段缺少注释,请读者参考PHP Manual的Oracle数据库函数部分)

4.4基于HTTP的Oracle登录

将以下代码加在PHP页面代码之前以确认Oracle登录。注意你必须正确设定$ SID。

if(!isset($PHP_AUTH_USER))

{

Header("WWW-authenticate: basic realm=\"$SID\"");

Header("HTTP/1.0 401 Unauthorized");

$title="Login Instructions";

echo"

You are not authorized to enter the site

\n";

exit;

}

else

{

if(!($conn=ora_logon("$PHP_AUTH_USER@$SID",$PHP_AUTH_PW)))

{

Header("WWW-authenticate: basic realm=\"$SID\"");

Header("HTTP/1.0 401 Unauthorized");

$title="Login Instructions";

echo"

You are not authorised to enter the site

\n";

exit;

}

}

?>

php->是什么意思

一、=>,->的意思:

->是对象执行方法或取得属性用的。

=>是数组里键和值对应用的。

二、用法

1、=>的用法数组中用于数组的key和value之间的关系例如:

$a=array('0'=>'1','2'=>'4',);echo$a['0'];echo$a['2'];

2、->的用法类中用于引用类实例的方法和属性例如:

classTest{functionadd(){return$this->var++;}var$var=0;}$a=newTest;

//实例化对象名称

echo$a->add();echo$a->var;

扩展资料

PHP中->代码如下:

<?php

class Car{

public$speed= 0;

//增加speedUp方法,使speed加10

public function speedUp(){

$this->speed+=10;

}

}

$car= new Car();

$car->speedUp();

echo$car->speed;

?>

PHP中=>代码如下:

<?php

//从数组变量$arr中,读取键为apple的值

$arr= array('apple'=>"苹果",'banana'=>"*",'pineapple'=>"菠萝");

$arr0=$arr["apple"];

if( isset($arr0))

{print_r($arr0);

}

?>

参考资料来源:百度百科- PHP(超文本预处理器)

百度百科- PHP运算符

本文链接:http://www.hnxdcx.com/html/87960407.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。