Home php教程 php手册 php入门学习知识点一 PHP与MYSql连接与查询_php入门_脚本之家

php入门学习知识点一 PHP与MYSql连接与查询_php入门_脚本之家

Jun 06, 2016 pm 08:37 PM
Inquire connect

php入门学习知识点一 PHP与MYSql连接与查询,学习php最重要的就是与数据库的交互。

一、连接数据库
 1、 mysql_connect: 开启 MySQL 链接

   mysql_connect('主机','用户名','密码')

2、 mysql_select_db: 打开一个数据库
mysql_select_db('数据库名',$链接标识符) //链接标识符不填写则默认为上一次打开的连接

3、 mysql_query("set names 'GBK'") 解决中文乱码问题;

   mysql_query("set names '编码(utf8或GBK)' ") //UTF8不能有“-”

二、查询数据

  1、mysql_query (SQL语句 ,连接标识符);

$sql="Select * FROM Test "
$result=mysql_query($sql) //连接标识符默认为上一次打开的链接

//获取错误信息

$result=@mysql_query($sql) or die(mysql_error())

2、获取查询到的结果

   a、 mysql_fetch_row($result);

     $row=mysql_fetch_row($result);
     echo $row[0];

b、 mysql_fetch_array($result);

$row=mysql_fetch_array($result);
echo $row[0];
echo $row['key'];


说明:mysql_fetch_array和mysql_fetch_row功能基本相同,只不过它除了可以用从0开始的偏移量作索引,还可以用域名作索引。
值返回下一行的所有域值,并将其保存至一个数组中,没有行时返回false。
Statement of this Website
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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to connect keep body fat scale How to connect keep body fat scale Mar 07, 2024 pm 04:50 PM

How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

12306 How to check historical ticket purchase records How to check historical ticket purchase records 12306 How to check historical ticket purchase records How to check historical ticket purchase records Mar 28, 2024 pm 03:11 PM

Download the latest version of 12306 ticket booking app. It is a travel ticket purchasing software that everyone is very satisfied with. It is very convenient to go wherever you want. There are many ticket sources provided in the software. You only need to pass real-name authentication to purchase tickets online. All users You can easily buy travel tickets and air tickets and enjoy different discounts. You can also start booking reservations in advance to grab tickets. You can book hotels or special car transfers. With it, you can go where you want to go and buy tickets with one click. Traveling is simpler and more convenient, making everyone's travel experience more comfortable. Now the editor details it online Provides 12306 users with a way to view historical ticket purchase records. 1. Open Railway 12306, click My in the lower right corner, and click My Order 2. Click Paid on the order page. 3. On the paid page

How to check your academic qualifications on Xuexin.com How to check your academic qualifications on Xuexin.com Mar 28, 2024 pm 04:31 PM

How to check my academic qualifications on Xuexin.com? You can check your academic qualifications on Xuexin.com, but many users don’t know how to check their academic qualifications on Xuexin.com. Next, the editor brings you a graphic tutorial on how to check your academic qualifications on Xuexin.com. Interested users come and take a look! Xuexin.com usage tutorial: How to check your academic qualifications on Xuexin.com 1. Xuexin.com entrance: https://www.chsi.com.cn/ 2. Website query: Step 1: Click on the Xuexin.com address above to enter the homepage Click [Education Query]; Step 2: On the latest webpage, click [Query] as shown by the arrow in the figure below; Step 3: Then click [Login Academic Credit File] on the new page; Step 4: On the login page Enter the information and click [Login];

How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset Mar 23, 2024 pm 01:16 PM

1. Place the earphones in the earphone box and keep the lid open. Press and hold the button on the box to enter the pairing state of the earphones. 2. Turn on the watch music function and select Bluetooth headphones, or select Bluetooth headphones in the watch settings function. 3. Select the headset on the watch to pair successfully.

Steps to connect game controller to Gohan Arcade Steps to connect game controller to Gohan Arcade Mar 19, 2024 pm 03:55 PM

How to connect Bluetooth controller to Gohan Arcade? Gohan Game Center is a game box used by many mobile game players. It contains a large number of popular game resources and rich game-related functions. Below, the editor will introduce the game controller connection method. Players, please take a look. 1. First go to the homepage of Gohan Game Center APP, and then click the "My" option in the lower right corner of the homepage; 2. Find the [Controller] function in the My page, the location is shown in the picture below, and click to go to settings; 3. Select to turn it on For the Bluetooth function of the mobile phone, confirm that the power of the controller is on; 4. Finally, follow the instructions of the controller to make a matching connection. If the connection is successful, you can use the mobile game to experience various games.

Three Ways to Fix Edge Your Connection Isn't Private Three Ways to Fix Edge Your Connection Isn't Private Mar 13, 2024 pm 01:30 PM

When you use the Edge browser to access web pages, have you ever encountered a prompt that your connection is not a dedicated connection, causing web browsing to fail? How is this going? Many friends don’t know how to deal with this problem. You can take a look at the following three solutions. Method 1 (simple and crude): In the edge browser, you can try to solve the problem of the website being inaccessible by entering the settings and turning off the security function, and then blocking location permissions in the website permissions. It is important to note that the effectiveness and duration of this approach may vary, and specific effects cannot be determined. After restarting your browser, you can try visiting the website to see if the issue is resolved. Method 2: Adjust the keyboard to English input

How to connect keep to Huawei bracelet How to connect keep to Huawei bracelet Mar 07, 2024 pm 09:46 PM

How to connect keep to Huawei bracelet? You can connect Huawei bracelet in keep software. Most users don’t know how to connect Huawei bracelet. Next is the graphic tutorial of how to connect keep to Huawei bracelet brought by the editor. Interested users come and take a look! How to connect keep to Huawei bracelet 1. First open the keep application, click [Me] in the lower right corner of the main page to enter the special area, and select [Smart Hardware]; 2. Then challenge to the My Smart Device function page, click [Add Device] in the middle; 3. Then on the page of selecting the device you want to add, select the [Smart Bracelet/Watch] function; 4. Finally, on the interface shown below, click on the Huawei watch model to connect.

What should I do if Google Chrome prompts that your connection is not a private connection? What should I do if Google Chrome prompts that your connection is not a private connection? Mar 07, 2024 pm 10:34 PM

What should you do if Google Chrome prompts you that the connection is not a private connection? What should you do if Google Chrome prompts you that the connection is not a private connection and cannot open the web page normally? When we use Google Chrome to surf the Internet, when we open the web page, we will be prompted that it is not a private link, causing us to be unable to access the Internet normally, which brings us great inconvenience. How should we solve this situation? The editor has compiled the Google Chrome browser below. It reminds you that your connection is not a private connection solution. If not, follow me and read on! What should I do if Google Chrome prompts that your connection is not a private connection? 1. Press "win+R" to start "Run", enter "mmc" and click "OK". 2. After the "Console" window pops up, click "File" and select "Add/Delete Management Order" from the pop-up menu.

See all articles